AHK can't run .vbs Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
iReynov
Posts: 2
Joined: 26 Feb 2018, 01:59

AHK can't run .vbs  Topic is solved

26 Feb 2018, 02:29

Greeting everyone!
It's not hard to understand that I don't "speak" any of program language. I dicided to write my 1st code or program that makes computer turn off the Ethernet and the turn it on immediately.
First of all I've created .bat file called disableint.bat that DISABLES Ethernet

Code: Select all

netsh interface set interface name="Ethernet" admin=DISABLED
And then I've created .bat file called enableint.bat that makes Ethernet turn on back again

Code: Select all

netsh interface set interface name="Ethernet" admin=ENABLED
Then I created .vbs file that make run .bat file without showing black window.
1st file called disableint.vbs

Code: Select all

'HideBat.vbs
CreateObject("Wscript.Shell").Run "disableint.bat", 0, True
2nd file called enableint.vbs

Code: Select all

'HideBat.vbs
CreateObject("Wscript.Shell").Run "enableint.bat", 0, True
I run all .vbs and they worked correctly.

Then I've created AHK script called disethernet.ahk

Code: Select all

F5::
RunWait, "C:\Users\User\Desktop\disableint.vbs
RunWait, "C:\Users\User\Desktop\enableint.vbs
return
After Pressing F5 it shows Error
Image

Can you help me what's the problem?

I know that I could make whole code way easier and shorter but it's my first work, it will next thing that I'll correct after successful launch.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: AHK can't run .vbs

26 Feb 2018, 03:00

You have an opening " but no closing " in your file name when using RunWait.
Either add 2 " and surround the file path with it, or leave them out completely.
Recommends AHK Studio
iReynov
Posts: 2
Joined: 26 Feb 2018, 01:59

Re: AHK can't run .vbs

26 Feb 2018, 03:21

Oh dude, you are my hero today! Thanks! lol
garry
Posts: 3771
Joined: 22 Dec 2013, 12:50

Re: AHK can't run .vbs

26 Feb 2018, 04:19

Then I created .vbs file that make run .bat file without showing black window.
.. and maybe not needs VBS script for this
win+R , type in cmd /?

%comspec% /k ; keep DOS window open
%comspec% /c ; close DOS window after executed

Example ahk-script :

Code: Select all

runwait,%comspec% /k netsh show helper             ;- see       DOS window , must close 
runwait,%comspec% /c netsh show helper             ;- see short DOS window  / cmd.exe close after command executed
run,%comspec% /c netsh show helper,,hide,          ;- see nothing ( hidden )  / cmd.exe close after command executed

sleep,5000
run,%comspec% /k netsh show helper,,hide,pid2      ;- see nothing but DOS is running ( cmd.exe )

sleep,20000                 ;- use ctrl+alt+del and see cmd.exe running which disappears after 20 seconds

process, exist, %PID2%
 status1 = %ErrorLevel%
if (status1 = pid2)         ;- close hidden DOS
  Process, Close, %pid2%
exitapp
RickC
Posts: 299
Joined: 27 Oct 2013, 08:32

Re: AHK can't run .vbs

26 Feb 2018, 15:49

I agree with garry, call netsh directly. For example, to toggle the network adapter using the F1 key, use the following:

Code: Select all

;https://autohotkey.com/boards/viewtopic.php?f=5&t=15205

adapter:="Local Area Connection" ; set to the adapter name

F1::
if(t:=!t)
    runwait,netsh interface set interface "%adapter%" disable,,hide
else
    runwait,netsh interface set interface "%adapter%" enable,,hide
return
Alternatively, wrap a PowerShell cmdlet in AHK to do exactly the same thing, e.g. (untested):

Code: Select all

psScript =
(
   Disable-NetAdapter -Name "Local Area Connection" -Confirm:$false
)
Run PowerShell.exe -Command %psScript%,, hide
... and use the Enable-NetAdapter cmdlet to undo the change.

Hope this helps...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: lostatlife and 58 guests