Sign in to follow this  
Followers 0
slaney30

Map a drive in WINPE using a variable from the first line of a text file

6 posts in this topic

I'm having some issues with an AUTOIT script and was wondering if someone could help me troubleshoot what I am doing wrong. I've looked through all the help files and can't seem to find out where I'm going wrong.

 

I have a script that maps the z drive successfully if I do not pull the variable from the text file. The following below works fine in the PE environment. Unfortunately I need to pull the variable from a text file on the machine that runs it because the server.domain.com will change depending upon machine.

Script 1 (works)

Global $server = 'server.domain.com'
MsgBox( 0, "variable value", $server)
DriveMapAdd("Z:", "\\" & $server & "\deployment", 0, "domain.com\useraccount", "(password)")

The script does not work:

Global $sFilePath = @ScriptDir & "\servervar.txt"


FileOpen($sFilePath, 0)


Global $server = FileReadLine( "servervar.txt" )


MsgBox(0, "variable value", $server)


DriveMapAdd("Z:", "\\" & $server & "\deployment", 0, "domain.com\useraccount", "(password)")
I added the Msgbox to confirm that the $server variable was indeed gathering the correct data, and it does have the correct data that i would expect.
 
Can anyone tell me why first script would work, but the 2nd will not? Like I said the 2nd script MsgBox is displaying the same data that i set manually with in the first script. I am new to autoit so if it's something really silly I apologize in advance.
 
Any help would be much appreciated!

Share this post


Link to post
Share on other sites



"doesn't work"; doesn't help much ;)

What error does the DriveMapAdd exit with? Throw a MsgBox after it, looking for @error.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Make sure there are no spaces or new lines in the file. That might be causing some issues.

Maybe try

Global $server = StringStripWS(FileReadLine( "servervar.txt" ), 8)
1 person likes this

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

"doesn't work"; doesn't help much ;)

What error does the DriveMapAdd exit with? Throw a MsgBox after it, looking for @error.

By "doesn't work" i meant it doesn't map the drive.

The @error that is displaying is 1.   

Share this post


Link to post
Share on other sites

else do a

ConsoleWrite("" & $server & "deployment")

maybe the fault come up if its a char problem

Share this post


Link to post
Share on other sites

 

Make sure there are no spaces or new lines in the file. That might be causing some issues.

Maybe try

Global $server = StringStripWS(FileReadLine( "servervar.txt" ), 8)

You are awesome! This is exactly what solved my problem. It must have been grabbing to many characters instead of only the characters listed. Thanks so much for your help!

Share this post


Link to post
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
Sign in to follow this  
Followers 0