it is always satisfying to complete a script. But no matter what, there are always tweaks. One issue with having a script contain information that you want hidden (password or hidden folder) in plain text is that it is easy for someone to open the file and see what the password is or the path to the hidden folder. One way to combat that is to convert the alphaNumeric entry to ANSI.
i.e.
MyChar =
Chr(65
) ' Returns A.
MyChar =
Chr(97
) ' Returns a.
MyChar =
Chr(62
) ' Returns >.
MyChar =
Chr(37
) ' Returns %.
See Ascii character Set for more info on this
Building off what TomRiddle posted, I took the code and added a couple functions that I use to convert AlphaNumeric to ANSI and this is what I came up with.
The path in this example is c:\program files\internet explorer
the sample password is SomePassWord
To convert a path or password to ANSI
c:\PathToScript\Scriptname.vbs thePassWord
c:\PathToScript\Scriptname.vbs "C:\Path\to\The folder"
I have not tried this with a space in the password so cannot say if it will work or not.
' * Call script with a command line containing letters or numbers to convert the password or folder path to ANSI
' - If the path contains a space, include "" surrounding the path in the arguement
' * Call the script with an ANSI commandline to convert the ANSI password or folder path to AlphaNumeric
' * Limitations
' - Do not use a , in the password as this will mess up the conversions
' - Inputbox has a max length limitation so the folder path cannot be too long. Using another method of displaying the ANSI string will prevent this
' - EX "C:\Users\xxxxxxxxX\AppData\Roaming\Local\Microsoft\Office Labs" is too long and will only display up to Office
Option Explicit
Dim wshShell : Set wshShell = WScript.CreateObject("WScript.Shell")
Dim ret, enterPassword, strPassword, strPath
strPassword = "83,111,109,101,80,97,115,115,87,111,114,100"
strPath = "67,58,92,80,114,111,103,114,97,109,32,70,105,108,101,115,92,73,110,116,101,114,110,101,116,32,69,120,112,108,111,114,101,114"
'Check if passing an arguement to the script
If WScript.Arguments.Count=0 Then
enterPassword = inputbox("Enter Password.")
Else
'If , in Arguement, assume converting ANSI to AlphaNumeric, else convert AlphaNumeric to ANSI
If InStr(Wscript.Arguments(0),",") Then
'Convert an ANSI arguement to AlphaNumeric
InputBox "Input",,ConvertToAlpha(Wscript.Arguments(0))
Else
'Convert an AlphaNumeric arguement to ANSI
InputBox "Input",,ConvertToANSI(Wscript.Arguments(0))
End If
'Quit script if passed an arguement
WScript.Quit
End If
If ConvertToANSI(enterPassword) = strPassword Then '"SomePassWord"
'msgbox "Access Granted"
wshShell.Run """" & ConvertToAlpha(strPath) & """"
Else
ret = MsgBox("Access Denied" & vbCr _
& "Do you want to run the script again?",vbYesNo)
If ret = vbYes Then
wshShell.Run """" & Wscript.ScriptFullName & """"
End If
End If
Function ConvertToANSI(theString)
'Split string on every character and convert char by char to ANSI
Dim i, CleanedString,strChar
For i = 1 To len(theString)
strChar = mid(theString,i,1)
If i = Len(theString) Then
CleanedString = CleanedString & asc(strChar)
Else
CleanedString = CleanedString & asc(strChar)& ","
End If
'WScript.Echo Asc(strChar)
Next
ConvertToANSI = CleanedString
End Function
Function ConvertToAlpha(theString)
'Split the string on , and convert to AlphaNumeric
Dim myArray, i, CleanedString
myArray = Split(theString,",")
For i = 0 To Ubound(myArray)
CleanedString = CleanedString & chr(myArray(i))
'WScript.Echo chr(myArray(i))
Next
ConvertToAlpha = CleanedString
End Function