» An ultimate catalog of computer data
Forum posts for smc.exe
Executing VBS Code in VBA with admin rights
how are you doing?
I want to execute VBS code in a VBA environment, in this case I am working in the VB editor in MS Excel 2010. Sadly I have no idea how to convert the VBS code so VBA is able to execute it.
To give an idea about what I am working on: I want to execute a VBS command prompt that needs Admin rights. This prompt will restart a process on a different PC in the network. The VBS code works perfectly fine, when executed via cmd. The reason I want to use VBA is that there are a lot PC's in the network and I want to use a loop to execute the VBS code for every PC.
OK, here is the VBS code:
strComputer = 'Computername'
Set objShell = CreateObject('Wscript.Shell')
Set objWMIService = GetObject('winmgmts:\' & strComputer & '
ootcimv2:Win32_Process')
intReturn = objWMIService.Create('c:Program Files (x86)SymantecSymantec Endpoint Protection12.1.1000.157.105Bin64smc.exe -stop', Null, Null, intProcessID)
Wscript.Sleep 10000
intReturn2 = objWMIService.Create('c:Program Files (x86)SymantecSymantec Endpoint Protection12.1.1000.157.105Bin64smc.exe -start', Null, Null, intProcessID)
The question is now, how do I get this code sample in to my VBA environment? I know how to execute the VBS file itself through VBA, but that is not enough, because I need a variable. Also the admin rights are up to the question.
OK, here is an update, I have now this code in my VBA, but I am not able to get things started, I also tried to implement the runas admin:
Sub run_vbs_script()
Dim strComputer As String
'Dim WshShell
Dim objShell
Dim objWMIService
Dim dDate As Date
strComputer = 'IEDBR8D60CR'
Set objShell = CreateObject('Wscript.Shell')
RunasStruser = 'runas /user:Username Domaindomain name'
objShell.Run RunasStruser, 0
objShell.SendKeys 'password'
Set objWMIService = GetObject('winmgmts:\' & strComputer & '
ootcimv2:Win32_Process')
intReturn = objWMIService.Create('c:Program Files (x86)SymantecSymantec Endpoint Protection12.1.1000.157.105Bin64smc.exe -stop', Null, Null, intProcessID)
dDate = DateAdd('s', 10, DateTime.Now)
Do While dDate > DateTime.Now
DoEvents
Loop
intReturn2 = objWMIService.Create('c:Program Files (x86)SymantecSymantec Endpoint Protection12.1.1000.157.105Bin64smc.exe -start', Null, Null, intProcessID)
Set objShell = Nothing
Set objWMIService = Nothing
End Sub
View complete forum thread with replies
Other posts related to smc.exe
See Related Forum Messages: Follow the Links Below to View Complete Thread
Executing VBS Code in VBA with admin rights