My first script...

Author Message
ksvane

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 5/23/2010
  • Status: offline
My first script... Sunday, May 23, 2010 10:26 PM (permalink)
0
This is without a doubt a really simple and basic script for most of you guys... but it took me a long time and I am proud to have finished it.
Say you have made a private folder and you hide it well on you hard disk, deep within some far off directory where no one will ever look.
This script allows you to acces this folder from eg. your desktop or your documents, but only if you type in the correct password.

Set WshShell = WScript.CreateObject("WScript.Shell")
a=inputbox("Please type the password.")
if a <> "[desired password here]" then
msgbox(a &" is wrong.")
End if
if a = "[desired password here]" then
msgbox (a &" is correct!")
Dim SH, txtFolderToOpen 
Set SH = WScript.CreateObject("WScript.Shell") 
txtFolderToOpen = "[Full path to folder here]" 
SH.Run txtFolderToOpen 
Set SH = Nothing 
End if


I don't know if the script is correct all the way, but it sure works.
Comments and suggestions are appreciated.
(I'm a Newbie with a capital N)
 
#1
    Kravis

    • Total Posts : 13
    • Scores: 0
    • Reward points : 0
    • Joined: 3/9/2010
    • Status: offline
    Re:My first script... Tuesday, May 25, 2010 9:02 AM (permalink)
    0
    A cleaner way to do it would be:

    Set WshShell = WScript.CreateObject("WScript.Shell")
    a=inputbox("Please type the password.")
    if a = "[desired password here]" then
       msgbox (a &" is correct!")
       Dim SH, txtFolderToOpen 
       Set SH = WScript.CreateObject("WScript.Shell") 
       txtFolderToOpen = "[Full path to folder here]" 
       SH.Run txtFolderToOpen 
       Set SH = Nothing 
    Else
       msgbox(a &" is wrong.")
    End if

    There's no reason to have the two if statements to check for the same value.
     
    #2
      ebgreen

      • Total Posts : 8227
      • Scores: 98
      • Reward points : 0
      • Joined: 7/12/2005
      • Status: offline
      Re:My first script... Tuesday, May 25, 2010 9:18 AM (permalink)
      0
      Thank you for sharing. Here are some comments that will hopefully help you in your journey to script Nirvana:

      1) Use Option Explicit. Read the docs to see what it does and there are several threads here discussing why you should.

      2) Use meaningful and descriptive variable names. Whether you use Hungarian or some other naming convention, at least use one and try to be consistent. It really does help.

      3) Solve problems and understand solutions. Start reading the questions that are posted here and try to solve them on your own. Even if you don't post your solution. For the ones that you can't solve, read the solution and try to understand why it is the solution.
      "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
      Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
      http://www.visualbasicscript.com/m_47117/tm.htm
       
      #3
        TomRiddle

        • Total Posts : 620
        • Scores: 12
        • Reward points : 0
        • Joined: 2/7/2008
        • Location: Australia
        • Status: offline
        Re:My first script... Sunday, May 30, 2010 11:43 PM (permalink)
        0
        Cool code,

        Had a play with it and spun it around. 

        If inputbox("Enter Password.")="Password" then
           msgbox "Access Granted"
           'your special code goes here.
        Else
           msgbox "Access Denied"
           Set objShell = WScript.CreateObject("WScript.Shell")
           objShell.Run Wscript.ScriptName
        End if

        As ebgreen said....

        And I recon there is nothing more satisfing than solving problems with script, have fun.
        -join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
         
        #4
          mbouchard

          • Total Posts : 2110
          • Scores: 29
          • Reward points : 0
          • Joined: 5/15/2003
          • Location: USA
          • Status: offline
          Re:My first script... Tuesday, June 15, 2010 1:37 AM (permalink)
          0
          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

          Mike

          For useful Scripting links see the Read Me First stickey!

          Always remember Search is your friend.
           
          #5
            TomRiddle

            • Total Posts : 620
            • Scores: 12
            • Reward points : 0
            • Joined: 2/7/2008
            • Location: Australia
            • Status: offline
            Re:My first script... Tuesday, June 15, 2010 10:40 AM (permalink)
            0
            Love it, this is jamming, you know like how one musician strikes a couple of chords and then others join in and make a new song.
             
            Also Mikes post reminds me of this one http://www.visualbasicscript.com/fb.ashx?m=2012 which was uber cool too.
             
            I am tempted to follow up with another script (fully encrypted path and MD5 hashed password)
            <message edited by TomRiddle on Tuesday, June 15, 2010 10:44 AM>
            -join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
             
            #6
              mbouchard

              • Total Posts : 2110
              • Scores: 29
              • Reward points : 0
              • Joined: 5/15/2003
              • Location: USA
              • Status: offline
              Re:My first script... Wednesday, June 16, 2010 12:45 AM (permalink)
              0
              Actually, that is where my inspiration for my code came from.  Thanks for linking it.  I had copied the code but forgot where I put it...

              And yes, I love this type of jamming.  Especially since it shows people new to scripting that there are normally multiple methods to reaching a goal. 
              Mike

              For useful Scripting links see the Read Me First stickey!

              Always remember Search is your friend.
               
              #7
                jessekielman

                • Total Posts : 1
                • Scores: 0
                • Reward points : 0
                • Joined: 6/21/2010
                • Status: offline
                Re:My first script... Monday, June 21, 2010 9:53 AM (permalink)
                0
                can someone tell me how it automaticly opens when i open a map e.g if open desktop

                If inputbox("Enter Password.")="jesse12" then
                   msgbox "Access Granted"
                   'your special code goes here.
                Else
                   msgbox "Access Denied"
                   Set objShell = WScript.CreateObject("WScript.Shell")
                   objShell.Run Wscript.ScriptName
                End if

                and then i can go on can someone tell me how to do that
                Grzz Jesse
                 
                #8

                  Online Bookmarks Sharing: Share/Bookmark

                  Jump to:

                  Current active users

                  There are 0 members and 1 guests.

                  Icon Legend and Permission

                  • New Messages
                  • No New Messages
                  • Hot Topic w/ New Messages
                  • Hot Topic w/o New Messages
                  • Locked w/ New Messages
                  • Locked w/o New Messages
                  • Read Message
                  • Post New Thread
                  • Reply to message
                  • Post New Poll
                  • Submit Vote
                  • Post reward post
                  • Delete my own posts
                  • Delete my own threads
                  • Rate post

                  2000-2012 ASPPlayground.NET Forum Version 3.9