Jump to content

Using Variables in paths...


BeeL
 Share

Recommended Posts

Hello Folks,

I was wondering if there is a simple way of using a variable as part of a path. For example I would need to use it in either the function "IniRead" or "drivemapadd" to just map a drive.

What I'm trying to do is get Autoit to take the contents of a file, (computer machine names) verify whether or not it is accessible, read a certain key from an ini file remotely (this is where I seem to be running into problems) and take that read key and append it to a 3rd file.

Please keep in mind I am VERY new at AutoIT and programming/scripting in general. I do apologize in advance if this topic has already been covered. (I tried doing a few searches and didn't come up with anything obvious) Any suggestions are greatly appreciated.

Thanks!

BeeL

Link to comment
Share on other sites

  • Moderators

Give us an example of what you have tried so we can help you better.

Here is an example of a variable with IniRead()

$Path = '"\\computername\pathtofile\file.ini"'
IniRead ( $Path, "section", "key", "default" )
Edited by big_daddy
Link to comment
Share on other sites

Give us an example of what you have tried so we can help you better.

I've tried either one of these and I seem to have no luck. I don't receive an immediate error, however the results aren't what they are supposed to be.

DriveMapAdd("k:", "\\"& $line &"\c$")

or

$CID = IniRead("\\"& $line &"\FP\MACHINE\dat32com.ini", "MyConnection", "Client Identifier", "NotFound")

In the line, rather than returning the value of the "Client Identifier" key, it returns the value NotFound. I just assumed that its because its not finding the path correctly because I'm not using the variable correctly.

I should also mention, $line = machine1 (for example)

Thanks again

BeeL

Edited by BeeL
Link to comment
Share on other sites

Sorry, I guess I should have posted more of the code.

This is the main part of my program.

;Main*************************

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

;MsgBox(0, "Line read:", $line)

Call ("check")

Wend

FileClose($file)

It then calls the check function which basically just pings the machine name to see if it is on.

;Check ***********************

Func check()

$var = Ping($line,250)

If $var Then

Call ("datalog")

Else

Call ("generic")

EndIf

EndFunc

From there it calls either datalog (if ping is successful) or generic (if ping times out)

;Datalog**********************

Func datalog()

DriveMapAdd("k:", "\\"&$line"\c$")

;Find information from INI file

$CID = IniRead("k:\FP\MACHINE\dat32com.ini", "MyConnection", "Client Identifier", "NotFound")

FileWrite ("c:\FPCID.txt", ""& $line &" = "& $CID &"" & @CR)

DriveMapDel("k:")

EndFunc

I've left out the Generic function because it seems to be the only part that works properly. All variables were declared before the main function.

Big Daddy: Does this mean the IniRead or DriveMapAdd commands look correct?

Thanks again, I do appreciate any help here.

BeeL

Link to comment
Share on other sites

Try this:

While 1

$line = FileReadLine($file)
If @error Then ExitLoop
;MsgBox(0, "Line read:", $line)
Call ("check")

Wend

FileClose($file)



Func check()

$var = Ping($line,250)
If $var Then
Call ("datalog")
Else
Call ("generic")
EndIf
EndFunc


Func datalog()

DriveMapAdd("k:", "\\" & $line & "\c$")

;Find information from INI file
$CID = IniRead("k:\FP\MACHINE\dat32com.ini", "MyConnection", "Client Identifier", "NotFound")

FileWrite ("c:\FPCID.txt", $line & " = " & $CID & @CR)

DriveMapDel("k:")

EndFunc

Is that what you wanted?

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

Try this:

Is that what you wanted?

Hi Kandie Man,

Looks like you've streamlined my code. I have just verified that it does properly map the drive however I guess what I am getting hung up on is the IniRead Function. I've manually looked through that ini file and I can see the information I'm trying to extract. The path, section and key are correct, however the value it's returning is the default (NotFound).

I guess that solves one problem. Do you guys have any idea why I'm not getting the correct data back from the IniRead function?

Thanks again,

BeeL

Link to comment
Share on other sites

Try this. I added one line of code to check to see if it is even detecting the ini file. If you don't get the error message, then it is detecting the file and something is wrong with the ini file or the iniread itself. Please post your ini file here so that i can help you further.

While 1

$line = FileReadLine($file)
If @error Then ExitLoop
;MsgBox(0, "Line read:", $line)
Call ("check")

Wend

FileClose($file)



Func check()

$var = Ping($line,250)
If $var Then
Call ("datalog")
Else
Call ("generic")
EndIf
EndFunc


Func datalog()

DriveMapAdd("k:", "\\" & $line & "\c$")

;Find information from INI file
If Not FileExists("k:\FP\MACHINE\dat32com.ini") Then msgbox(0,"Error!","k:\FP\MACHINE\dat32com.ini doesn't exist.")
$CID = IniRead("k:\FP\MACHINE\dat32com.ini", "MyConnection", "Client Identifier", "NotFound")

FileWrite ("c:\FPCID.txt", $line & " = " & $CID & @CR)

DriveMapDel("k:")

EndFunc

-The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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...