Jump to content

Can this VBscript be turned into an AutoIt exe?


Mitt
 Share

Recommended Posts

I have this vbscript that works well I just need to convert it into an exe to hide the login information from users. It looks for the next available drive letter and maps the network share to it and then runs a file from that location. Once the file has been executed the drive is unmapped.

I am very new to AutoIt but have found it does almost everything and just need a little help if possible.

'Find out next available drive letter
set objFSO=CreateObject ("Scripting.FileSystemObject")
set colDrives=objFSO.Drives
strAvailableDrive=Asc("c")
while objFSO.DriveExists(Chr(strAvailableDrive)+":")
 strAvailableDrive=strAvailableDrive+1
wend

'Change to uppercae and set to char plus add : to the drive letter
strDrive = UCASE(Chr(strAvailableDrive))+":"

'Set network connection settings
strNetworkShare = "\\10.10.10.1\Share"
strNetworkUsername = "Administrator"
strNetworkPassword = "admin"
strRunExe = "custom.exe"
strPersistant = "FALSE"

'Connect to network share and map to local drive
Set objNetwork = WScript.CreateObject("WScript.Network")
On Error Resume Next
  objNetwork.MapNetworkDrive strDrive, strNetworkShare, strPersistant, strNetworkUsername, strNetworkPassword
  WScript.Run "" + strDrive + ""\"" + strRunExe +""

'Unmap Network Drive after file has completed
objNetwork.RemoveNetworkDrive ""+ strDrive +""
Link to comment
Share on other sites

This is very easy.

- Change all "Set" to "Dim"

- Place dollar sign in front of variable, array, and object names

- Change CreateObject to ObjCreate

- Strip "On Error Resume Next"

- Wrap object function calls with parantheses: i.e. myObj.Function param1, param2 -> $myObj.Function($param1, $param2)

- Change apostrophe's to semi-colons for comments

Link to comment
Share on other sites

Also check out DriveMapAdd DriveMapDel and ShellExecuteWait or RunWait in the Help file

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

  • 1 month later...

#include <Constants.au3>

;Find out next available drive letter

Dim $objFSO = ObjCreate("Scripting.FileSystemObject")

$strAvailableDrive = Asc("C")

while $objFSO.DriveExists(Chr($strAvailableDrive)&":")

$strAvailableDrive = $strAvailableDrive+1

wend

;Set drive letter from first available drive

$strDrive = Chr($strAvailableDrive)&":"

;Set network connection settings

$strNetworkShare = "\\10.10.10.1\"

$strNetworkUsername = "Administrator"

$strNetworkPassword = "lamopassword"

$strExe = "custom.exe"

$strRun = "" & $strDrive & "\SomePath\" & $strExe & ""

$strPersistant = "FALSE"

;Prepare progress bar

Dim $counter

Dim $max

Dim $pause

Dim $msgBoxAnswer

$max = 100

$pause = 2

ProgressOn("MY Custom Title","","","50","50",16)

;Connect to network share and map to local drive

Dim $objNetwork = ObjCreate("WScript.Network")

$objNetwork.MapNetworkDrive($strDrive, $strNetworkShare, $strPersistant, $strNetworkUsername, $strNetworkPassword)

;Execute install passing mapped drive letter as parameter 1 (needed by .bat file)

Run(@ComSpec & " /c " & $strRun & " " & $strDrive,"",@SW_HIDE)

$strProcess = "CustomProcess.exe"

For $counter = 1 to $max

If $counter >= 99 AND ProcessExists($strProcess) <> 0 Then

$counter = 99

ElseIf $counter < 20 Then

ProgressSet(($counter/$max)*100,"",($counter/$max)*100 & "% Completed")

Sleep($pause * 2 * 1000)

ElseIf $counter < 99 AND ProcessExists($strProcess) <> 0 Then

ProgressSet(($counter/$max)*100,"",($counter/$max)*100 & "% Completed")

Sleep($pause * 1000)

ElseIf $counter <= 99 AND ProcessExists($strProcess) = 0 Then

ProgressSet(($counter/$max)*100,"",($counter/$max)*100 & "% Completed")

If $counter < 95 Then

$counter = $counter + 5;

EndIf

Sleep(500)

EndIf

Next

;Process has closed, 100% complete

ProgressSet(100,"Process has completed successfully","100% Complete")

;Unmap Network Drive

$objNetwork.RemoveNetworkDrive ("" & $strDrive & "")

Sleep(2000)

$msgBoxAnswer = MsgBox(0,"Custom Setup", "Setup is complete")

If $msgBoxAnswer = 1 Then ProgressOff()

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...