Fine tuning vbscript -


i writing vbscript pass date/time value (especially before 2:00 last day value). there fine tuning instead of pass value batch , use batch1 call vbscript , batch2 (created in vbscript)? lot

dim datemonth, dateday, dateyear, dateyy, datemmm, mm, pdateday 'check time if hour(now) < 2 'before 2am, count last working day     datemonth   = month(dateadd("d",-1,now))     dateday     = day(dateadd("d",-1,now))     dateyear    = year(dateadd("d",-1,now))     dateyy      = right(year(dateadd("d",-1,now)),2)     timehh      = hour(now)     timemm      = minute(now) else     datemonth   = month(now)     dateday     = day(now)     dateyear    = year(now)     dateyy      = right(year(now),2)     timehh      = hour(now)     timemm      = minute(now)    end if  mm = array("","jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec") datemmm = mm(datemonth) if datemonth < 10       datemonth = "0" & datemonth end if if dateday < 10     dateday = "0" & dateday end if if timehh < 10      timehh = "0" & timehh end if if timemm < 10      timemm = "0" & timemm end if   set objfso=createobject("scripting.filesystemobject")  ' create log file dim ofso, otxtfile, curdir set ofso = createobject("scripting.filesystemobject")        curdir = ofso.getabsolutepathname(".") strfile = "\datetime.bat" if ofso.fileexists(curdir & strfile)         ofso.deletefile curdir & strfile end if  strvalue = "set date_mmdd=" & datemonth & dateday strvalue = strvalue & vbcrlf & "set date_mm=" & datemonth strvalue = strvalue & vbcrlf & "set date_mmm=" & datemmm strvalue = strvalue & vbcrlf & "set date_dd=" & dateday strvalue = strvalue & vbcrlf & "set date_hhmm=" & timehh & timemm strvalue = strvalue & vbcrlf & "set time_hh=" & timehh strvalue = strvalue & vbcrlf & "set time_mm=" & timemm   set otxtfile = ofso.createtextfile(curdir & strfile)  otxtfile.writeline(strvalue)  wscript.echo strvalue  set otxtfile = nothing set ofso = nothing   

i'm not sure if want run batch script directly vbscript, in case option available, don't need write generate file @ - can pass in date , other info using command-line parameters.

in example below, simplified date code , passed fields batch file, echo them vbscript show in message box. can adapt needs.

test.vbs:

option explicit  dim rundate : rundate = now() if hour(rundate) < 2 rundate = dateadd("d", -1, rundate)  dim runyear : runyear = year(rundate) dim runmonth : runmonth = monthname(month(rundate), true) dim runday : runday = day(rundate) ' etc...  dim parameters : parameters = join(array(runyear, runmonth, runday), " ")  ' see https://stackoverflow.com/a/45284140/534406 below code  const wshrunning = 0 const wshfinished = 1 const wshfailed = 2  dim shell : set shell = createobject("wscript.shell") dim exec : set exec = shell.exec("test.bat " & parameters)  while exec.status = wshrunning     wscript.sleep 50 wend  dim output  if exec.status = wshfailed     output = exec.stderr.readall else     output = exec.stdout.readall end if  wscript.echo output 

test.bat

@echo off set year=%1 set month=%2 set day=%3 echo year %year% month %month% day %day% 

output (for today, after 2am):

year 2017 month aug day 15 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -