Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using system variables when executing program via command-line 1

Status
Not open for further replies.

JustScriptIt

Technical User
Oct 28, 2011
73
US
I have a script that will shut down a service based on the password a user supplied.

However, I prefer to use system variable, because user may have Program Files in a different drive.

This is what I have so far

Code:
Option Explicit

Dim objPassword, strPassword, objShell, objWMIService, intProcessID, intReturn

Set objPassword = CreateObject("ScriptPW.Password") 
WScript.StdOut.Write "Please enter your password:" 

strPassword = objPassword.GetPassword() 

Set objShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2:Win32_Process")


objWMIService.Create(%programfiles% & " \Symantec Endpoint Protection\smc.exe -stop " & strPassword)

And I get the error


(17, 22) Microsoft VBScript compilation error: Invalid character


Thank you for your help!
 
I expanded the variable towards the end of the script, but it is still not working

Code:
Option Explicit

Dim objPassword, strPassword, objShell, objWMIService, PATH

Set objPassword = CreateObject("ScriptPW.Password") 
WScript.StdOut.Write "Please enter your password:" 

strPassword = objPassword.GetPassword() 

Set objShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2:Win32_Process")

[b]objShell.ExpandEnvironmentStrings( "PATH=%programfiles%" )[/b]

[b]objWMIService.Create(PATH & "\Symantec Endpoint Protection\smc.exe -stop " & strPassword)[/b]
 
Replace this :
Code:
[b][COLOR=red]objShell.ExpandEnvironmentStrings( "PATH=%programfiles%" )[/color][/b]
by this :
Code:
[b][COLOR=green]PATH = objShell.ExpandEnvironmentStrings("%programfiles%")[/color][/b]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top