Hey Guys - I hope this is an easy one, I couldn't find much searching.
I'm trying to run a Batch file via RunAs. That part works fine. The issue comes whenI try to add some variables (Start Date and End Date). It doesn't like them, won't even prompt me for a password.
Is there a way I can fix this? Or even just open up a run as CMD via VBS RunAs then use that same window to call the Batch with the Params?
Code Issues:
context code:
- Matt
"If I must boast, I will boast of the things that show my weakness
I'm trying to run a Batch file via RunAs. That part works fine. The issue comes whenI try to add some variables (Start Date and End Date). It doesn't like them, won't even prompt me for a password.
Is there a way I can fix this? Or even just open up a run as CMD via VBS RunAs then use that same window to call the Batch with the Params?
Code Issues:
Code:
shell.Run "runas /user:<username> /netonly C:\Users\<username>\Desktop\MATS_Metrics_MC\MATS_Metrics.bat" '& fmtStartDate & fmtEndDate,1,True
context code:
Code:
Dim EndDate, StartDate, fmtEndDate, fmtStartDate, BatFileLoc, sPathToRunAs, Password, cmd
'Batch File to Run
BatFileLoc = "C:\Users\<username>\Desktop\MATS_Metrics_MC\MATS_Metrics.bat"
'Location to RunAs (to activate window)
sPathToRunAs = "C:\Windows\System32\runas.exe"
'Find the Last Friday
EndDate = DateAdd("d",-(Weekday(Date)+1),Date)
'StartDate would be the LastFriday -6 Days to get the Saturday before
StartDate = DateAdd("d",-6,EndDate)
'Format the dates Year, Month, Day (2013-09-04)
fmtEndDate = Year(EndDate) & "-" & Right(String(2,"0") & Month(EndDate),2) & "-" & Right(String(2,"0") & Day(EndDate),2)
fmtStartDate = Year(StartDate) & "-" & Right(String(2,"0") & Month(StartDate),2) & "-" & Right(String(2,"0") & Day(StartDate), 2)
'Enter Mooncake Password via InputBox
Password = inputbox("Enter Password","Password") & "~"
'Call the MDS Batch, Enter Password, Wait for it to complete
set shell=createobject("wscript.shell")
[COLOR=#CC0000]shell.Run "runas /user:<username> /netonly C:\Users\<username>\Desktop\MATS_Metrics_MC\MATS_Metrics.bat" '& fmtStartDate & fmtEndDate,1,True[/color]Wscript.Sleep 100
shell.SendKeys Password
- Matt
"If I must boast, I will boast of the things that show my weakness