Link to home
Create AccountLog in
Avatar of John Darby
John DarbyFlag for United States of America

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%\desktop\gpresult.html
start c:\users\%username%\desktop\gpresult.html

Thank you!
JohnD
SOLUTION
Avatar of merowinger
merowinger
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of John Darby

ASKER

Thanks Merowinger,
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
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.Shell")
ObjShell.run "C:\Windows\WinSxS\x86_microsoft-windows-g..policy-cmdlinetools_31bf3856ad364e35_6.3.9600.17415_none_d0555e62f7544147\gpresult /H c:\users\%username%\desktop\gpresult.html",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\%username%\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
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?
Avatar of Bill Prew
Bill Prew

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 

Open in new window

~bp
Thanks Bill!

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

Open in new window

~bp
I changed the path to c:\windows\system32
So, are you still having a problem now?

~bp
The gpresult produces the file, but the new email message doesn't spawn
I don't see strSMTPRelay defined?

~bp
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thank you so much; I now need to find the SMTPRelay inside my company :)