John Darby
asked on
CMD script into VBS
Greetings,
I have a bit of CMD script I would like to execute using VBS. Could you help me with how to do this in VBS:
gpresult /H c:\users\%username%\deskto p\gpresult .html
start c:\users\%username%\deskto p\gpresult .html
Thank you!
JohnD
I have a bit of CMD script I would like to execute using VBS. Could you help me with how to do this in VBS:
gpresult /H c:\users\%username%\deskto
start c:\users\%username%\deskto
Thank you!
JohnD
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Does this look like a start? My aim is to open a new email with the file attached...
'***GPUPDATE wrapper for UES Client Data GPO Use***
Set objShell = CreateObject("Wscript.Shel l")
ObjShell.run "C:\Windows\WinSxS\x86_mic rosoft-win dows-g..po licy-cmdli netools_31 bf3856ad36 4e35_6.3.9 600.17415_ none_d0555 e62f754414 7\gpresult /H c:\users\%username%\deskto p\gpresult .html",1,t rue
'ObjShell.run "start c:\users\%username%\deskto p\gpresult .html",1,t rue
'Param Values
strSMTPTo = "v-jodar@company.com"
strTextBody = "This is my Computer's Gpesult"
strSubject = "Gpresult from my Computer"
strAttachment = "c:\users\%username%\deskt op\gpresul t.html"
'Message Formatting
Set oMessage = CreateObject("CDO.Message" )
oMessage.Configuration.Fie lds.Item(" http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMessage.Configuration.Fie lds.Item(" http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
oMessage.Configuration.Fie lds.Item(" http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oMessage.Configuration.Fie lds.Update
'Message Params
oMessage.Subject = strSubject
oMessage.To = strSMTPTo
oMessage.TextBody = strTextBody
oMessage.AddAttachment strAttachment
'***GPUPDATE wrapper for UES Client Data GPO Use***
Set objShell = CreateObject("Wscript.Shel
ObjShell.run "C:\Windows\WinSxS\x86_mic
'ObjShell.run "start c:\users\%username%\deskto
'Param Values
strSMTPTo = "v-jodar@company.com"
strTextBody = "This is my Computer's Gpesult"
strSubject = "Gpresult from my Computer"
strAttachment = "c:\users\%username%\deskt
'Message Formatting
Set oMessage = CreateObject("CDO.Message"
oMessage.Configuration.Fie
oMessage.Configuration.Fie
oMessage.Configuration.Fie
oMessage.Configuration.Fie
'Message Params
oMessage.Subject = strSubject
oMessage.To = strSMTPTo
oMessage.TextBody = strTextBody
oMessage.AddAttachment strAttachment
ASKER
Weird behavior, the new email message doesn't spawn and it also cannot find the newly created gpresult.html (the file is there, but the strAttachment path seems to be invalid?
Haven't studied the code, but this could help.
'***GPUPDATE wrapper for UES Client Data GPO Use***
Set objShell = CreateObject("Wscript.Shell")
strUserName = objShell.ExpandEnvironmentStrings("%USERNAME%")
strExec = "C:\Windows\WinSxS\x86_microsoft-windows-g..policy-cmdlinetools_31bf3856ad364e35_6.3.9600.17415_none_d0555e62f7544147\gpresult /H c:\users\" & strUser & "\desktop\gpresult.html"
ObjShell.run strExec,1,true
'ObjShell.run "start c:\users\%username%\desktop\gpresult.html",1,true
'Param Values
strSMTPTo = "v-jodar@company.com"
strTextBody = "This is my Computer's Gpesult"
strSubject = "Gpresult from my Computer"
strAttachment = "c:\users\" & strUser & "\desktop\gpresult.html"
'Message Formatting
Set oMessage = CreateObject("CDO.Message")
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oMessage.Configuration.Fields.Update
'Message Params
oMessage.Subject = strSubject
oMessage.To = strSMTPTo
oMessage.TextBody = strTextBody
oMessage.AddAttachment strAttachment
~bp
ASKER
Thanks Bill!
I see a similar issue my code had possessed: line 28 ref to strAttachment is not finding the file
I see a similar issue my code had possessed: line 28 ref to strAttachment is not finding the file
In the strExec command line, is this really the valid path to the executable, the ".." in the middle seems suspect.
C:\Windows\WinSxS\x86_microsoft-windows-g..policy-cmdlinetools_31bf3856ad364e35_6.3.9600.17415_none_d0555e62f7544147\gpresult
~bp
ASKER
I changed the path to c:\windows\system32
So, are you still having a problem now?
~bp
~bp
ASKER
The gpresult produces the file, but the new email message doesn't spawn
I don't see strSMTPRelay defined?
~bp
~bp
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you so much; I now need to find the SMTPRelay inside my company :)
ASKER
to prompt the user to locate the file and email it to me, maybe the "start" is a less-helpful approach? Would you suggest using some kind of window popup or spawning a new email with the default email handler with the file attached?
Appreciate your guidance!
JohnD