开发者

VBScript and presenting an input box

I am writing a script to capture the login time. In the final production, there would be no input from any user. However I am testing it and I wanted to know how I add extra code to determine that

  1. If its in 'debug' mode AND
  2. The user that is logging in is me (lets say my username is joe.smith on the domain called EXAMPLE)

then present an input box to allow me to type the开发者_开发问答 date, time for logging in.

All other users would never see this and it would capture today with the system time.

I would also like to hide the code so if the script is opened by the wrong person, they wouldnt be able to make heads or tails of whats going on.


You can use a command line parameter as Matt says to set the script into debug mode, eg

dim isdebug: isdebug = WScript.Arguments.Named.Exists("debug")
WScript.Echo("in debug mode: " & isdebug)

Which you can invoke with

wscript debugscript.vbs /debug

To get the current user name, you can use either the WMI Service or the WScript.Network object.

Once you have the username, you can conditionally throw up an InputBox and collect the value returned:

dim date_: date_ = Now()
if isdebug and username = "me"  then
    dim value: value = CDate(InputBox("enter the date and time (dd/mm/yyyy hh:mm:ss)", "please", Now()))
    ' validate the input here
    date_ = CDate(value) 
end if

And finally, to obfuscate your code you could use the Scripting.Encoder although it looks like this doesn't seem to be supported on Vista or Windows 7. There does seem to be a few hits on googling the phrase obfuscating vbscript, anyway.


Most of this sounds like it can be resolved by the logic of the script.

Have a command line parameter (debug is an appropriate name) and then have some if logic in the code to do as you wish (present the input box).

For the code obfuscation, I don't know how this could be done in vbscript. Windows scripting host works with JavaScript as well though and there are plenty of tools on the web for making JS harder to read. Maybe you want to look a using JS...

HTH, Matt


I think you can check the property App.LogMode to see if you are in 'debug' mode or not. If it is 0 then you are running debug mode and if it is 1 you are not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜