here is my VBScript
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\Program Files\TrueCrypt\TrueCrypt.exe", 0 , false
It says it can't find it.
Taken from here
You can get around this by surrounding the path in quotes. But to do so, you need to escape them correctly(with "), so:
WshShell.Run """C:\Program Files\TrueCrypt\TrueCrypt.exe"""
Either put more quotes around the path, or use the old style string for "Program Files" - Progra~1.
The following example works on my machine:
<package>
<job id="truecrypt">
<script language="VBScript">
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """C:\Program Files\TrueCrypt\TrueCrypt.exe""", 0 , false
</script>
</job>
</package>
You can try the following:
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""C:\Program Files\TrueCrypt\TrueCrypt.exe""")
Set objShell = Nothing
Related
I have this VBScript:
On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
myKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\example"
WshShell.RegWrite myKey, "C:\Program Files (x86)\example.exe", "REG_SZ"
Set WshShell = Nothing
which adds
"C:\Program Files (x86)\example.exe"
to the startup registry
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\example"
Now I also want to add
"C:\Program Files (x86)\example.exe"
to the startup registry
"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\example"
How can you do that in only ONE SINGLE VBScript?
I tried to just modify this code:
On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
myKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\example"
WshShell.RegWrite myKey, "C:\Program Files (x86)\example.exe", "REG_SZ"
Set WshShell = Nothing
so that it would add the program to HKEY_LOCAL_MACHINE and then paste it underneath, but that didn't work.
Dim wshShell
Dim myKey
Set wshShell = CreateObject("WScript.Shell")
myKey = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\example"
wshShell.RegWrite myKey, "C:\Program Files (x86)\example.exe", "REG_SZ"
I am trying to pass an exe path in the VBScript to call it automatically. Please suggest.
Path to pass :
C:\Program Files\TSVN\bin\Tor.exe"/command:repobrowser
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run(""C:\Program Files\TSVN\bin\TProc.exe"/command:repobrowser"") 'Not working
Set objShell = Nothing
The quotes have not been escaped correctly causing in string to be incorrectly terminated, try this;
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("""C:\Program Files\TSVN\bin\TProc.exe""/command:repobrowser")
Set objShell = Nothing
The string is equivalent to
"C:\Program Files\TSVN\bin\TProc.exe"/command:repobrowser
Useful Links
Adding quotes to a string in VBScript
My code is
Set WshShell = CreateObject("WScript.shell")
for i = 0 to 50
WshShell.SendKeys(chr(175))
next
Process.Start("CMD", "/C start chrome.exe http://www.example.com")
It sets the volume to full, then opens chrome to example.com. But when I run it I get this error:
Cannot use parentheses while calling a Sub
How can I get it to raise the volume, and go to the webpage?
Try like this way :
Option Explicit
Dim URL,WshShell,i
URL = "www.yahoo.com"
Set WshShell = CreateObject("WScript.shell")
For i = 0 to 50
WshShell.SendKeys(chr(175))
Next
WshShell.run "CMD /C start chrome.exe " & URL & "",0,False
wshshell.run "www.youtube.com"
VBScript requires the CALL keyword when calling a sub with parenthesis. You can either write the code like this:
Set WshShell = CreateObject("WScript.shell")
For i = 0 To 50
WshShell.SendKeys Chr(175)
Next
Process.Start "CMD", "/C start chrome.exe http://www.example.com"
...or like this:
Set WshShell = CreateObject("WScript.shell")
For i = 0 To 50
Call WshShell.SendKeys(Chr(175))
Next
Call Process.Start("CMD", "/C start chrome.exe http://www.example.com")
Note: you don't get this error when calling a function and using its return value, like this:
Dim strTest
strTest = SomeFunction()
...because VBScript always requires the parenthesis when a function is used in an assignment.
This way works for me.
set wshshell = wscript.CreateObject("wscript.shell")
wshshell.run "chrome.exe https://stackoverflow.com"
You can change chrome.exe to whatever browser or the website to whatever you want
If a computer run's the script on Wednesday, i want that it creates a %computername*.txt file in a netwok map. In batch script i can to it with %computername%.txt, what code can i use it for VBS script?
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
If DatePart("W",Date) = 4 Then
'Today is Wednesday, so run the virus scan
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("\\server\Avast Scan Log\%COMPUTERNAME%.txt")
WshShell.Run """C:\Program Files\Alwil Software\Avast4\aswcmd"" M: /m /*", , True
End If
>> WScript.Echo CreateObject("WScript.Shell").ExpandEnvironmentStrings("%COMPUTERNAME%")
>>
WINXPSP3
>> WScript.Echo CreateObject("WScript.Network").Computername
>>
WINXPSP3
Use the WshNetwork object to get the computer name as suggested. It looks like this.
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = CreateObject("WScript.Network")
strComputer = WshNetwork.ComputerName
If DatePart("W",Date) = 4 Then
'Today is Wednesday, so run the virus scan
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("\\server\Avast Scan Log\" & strComputer & ".txt")
WshShell.Run """C:\Program Files\Alwil Software\Avast4\aswcmd"" M: /m /*", , True
End If
I have written a small vbs script to download and change the registry for the current users wallpaper. however it copies and does the change but the wallpaper does not change... any ideas on errors in the below code?
Option Explicit
Dim WshShell, strValue, sleepTime, oFSO
strValue = "C:\wallpaper.bmp"
sleepTime = 30000
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.CopyFile "\\anspksnms1\OSD\Scripts\wallpaper\wallpaper.bmp", "C:\"
Set WshShell = WScript.CreateObject("Wscript.Shell")
WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", strValue
WScript.Sleep sleepTime
WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters", 1, False
Set WshShell = Nothing
I'm not much of a vbscripter, but maybe try this?
wshShell.run "cmd /c RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters", 1, True