Jump to content
Sign in to follow this  
grimmlock

If @computername =

Recommended Posts

grimmlock

I need some help with creating a piece of code that will allow me to check the name of the workstation, that my new script is going to run on, against the list of computer in a txt file, then if the name of the workstation matches one of the workstation names in the txt file then do the following, but if the workstation does not match then do nothing.

I think I need to use @computername to determine the current name of the workstation.

Edited**

If @computername = ; (one of the workstations in my txt file) Then <<<<<<<< this is where i need the help
$list = WinList("Polaris Shortcut Bar - ")
If $list [0][0] > 1 Then
;~ msgbox(0, "", "You have one instance open")
WinClose("Polaris Shortcut Bar - ")
;~ Sleep (1000)
msgbox(0, '', 'You have one instance open')
EndIf
Sleep(10)
Else
Endif

Thanks,

Grimm

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites
grimmlock

Just edited my code to inlcude (i think) what I am trying to do. However i have tried various snippets like GuiCtrlRead, FileRead none of them are taking my computername and seeing if it is a match to any of the workstations in my txt file.

Thanks,

Grimm

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites
JohnOne

So you know how to compare your text file values against @Compu...?

In your code it is just doing something with windows.

You want the likes of FileRead, or _FileReadToArray, and a loop to test.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
grimmlock

Thank you JohnOne, I was able to solve my problem by adding just a few (now) simple lines.

Here is the final code that works:

Global $file1 = FileRead("File location.txt")

While 1


Local $list = WinList("Polaris Shortcut Bar - ")
Local $name = @ComputerName

If $name = $file1 Then
;~ msgbox(0, "", $file1)
;~ Exit

Local $list = WinList("Polaris Shortcut Bar - ")
  If $list [0][0] > 1 Then
  WinClose("Polaris Shortcut Bar - ")
  msgbox(0, '', 'You have one instance open')
  EndIf
  Sleep(10)
Else
;~  msgbox(0, "", "NOT")
;~  Exit
EndIf
Wend

Thanks

Grimm

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites
grimmlock

Ok so after testing this I added more computers to the list and now I am having issues again...

In the txt file that contains the computer list, all the computers are seperated by "|". So when I run the script the @computername no longer is being verified against the file, I think it because it might think that the list of computer is one big long list. I tried putting the computer names on seperate lines in the txt file and still now luck. I have a feeling that this can be fixed by an array but I do not understand arrays. I am hoping that someone might be able to help me build an array or something else that will allow the @computername to be verified against the txt file.

Please?

Thanks

Grimm


Thanks

Grimm

Share this post


Link to post
Share on other sites
JLogan3o13

I would definitely suggest an array. Put them all in a flat text file and then do something like this:

#include <File.au3>

Local $aArray
 _FileReadToArray(@DesktopDir & "\1.txt", $aArray)
 
 For $i = 1 To $aArray[0]
  If @ComputerName = $aArray[$i] Then
   ;do stuff
  EndIf
 Next

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

Share this post


Link to post
Share on other sites
grimmlock

Thank you sooo much that worked like a charm .... thank you!!!!! :thumbsup:

Thanks

Grimm


Thanks

Grimm

Share this post


Link to post
Share on other sites
grimmlock

ok one more quick question. If I change the _FileReadtoArray from (@DesktopDir & "1.txt", $aArray) to a networked share ("infotechitmy scripts1.txt", $aArray) I get the following error:

For $i = 1 to Array[0] with the ^ pointing to [0]. Error: Subscript used with non-array variable.

Any thoughts?

Thanks

Grimm

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites
BrewManNH

Yes, error checking.

Use _ArrayDisplay on the array returned to see if there's anything in it. Check to see if there's an error from _FileReadToArray. Anything else you can think of to check for why it's not giving you the array you're expecting.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
kylomas

grimlock,

Either your format for the network share is wrong or you are not giving it time to complete. Either way $array is not an array.

If the reason is network delay then you might try a loop like this (not tested)

Local $aArray, $try_cnt = 0
_FileReadToArray(@DesktopDir & "\1.txt", $aArray)

while not isarray($array) 
    _FileReadToArray(@DesktopDir & "\1.txt", $aArray)
    sleep(2000)
    $try_cnt += 1
    if $try_cnt > 9 then 
        msgbox($mb_ok,'ERROR','some kind of error stuff')
        ExitLoop
    EndIf
wend

 For $i = 1 To $aArray[0]
  If @ComputerName = $aArray[$i] Then
   ;do stuff
  EndIf
 Next

kylomas

edit: fingers too slow...BrewmanNH beat me again...

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
grimmlock

Klomas thank you for the reply I tried you code, and I had to change the isarray($array) to isarray($aArray) after that is seems to open but then after about 10 seconds it pops up the Error msgbox.

grimlock,

Either your format for the network share is wrong or you are not giving it time to complete. Either way $array is not an array.

If the reason is network delay then you might try a loop like this (not tested)

Local $aArray, $try_cnt = 0
_FileReadToArray(@DesktopDir & "\1.txt", $aArray)

while not isarray($array)
_FileReadToArray(@DesktopDir & "\1.txt", $aArray)
sleep(2000)
$try_cnt += 1
if $try_cnt > 9 then
msgbox($mb_ok,'ERROR','some kind of error stuff')
ExitLoop
EndIf
wend

For $i = 1 To $aArray[0]
If @ComputerName = $aArray[$i] Then
;do stuff
EndIf
Next

kylomas

edit: fingers too slow...BrewmanNH beat me again...

Thanks,

Grimm

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites
grimmlock

BewManNH, thank you for the reply as well. I put in the _arraydisplay just under _filereadtoarray and it gives me the same Array[0] error :(

Yes, error checking.

Use _ArrayDisplay on the array returned to see if there's anything in it. Check to see if there's an error from _FileReadToArray. Anything else you can think of to check for why it's not giving you the array you're expecting.

Thanks,

Grimm

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites
JLogan3o13

Comment that section out, and just see if you can get the array to display.


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

Share this post


Link to post
Share on other sites
grimmlock

So I commented out what I hope was the right stuff

This is what I have and it doesn't show me anything about the array.

#include <File.au3>

Local $list = WinList("Shortcut Bar - ")
Local $aArray
_FileReadToArray("\\192.168.26.17\IT\My Scripting Workshop\BranchPCs\BranchPCs.txt", $aArray)
_ArrayDisplay($aArray, "")


;~ For $i = 1 To $aArray[0]
;~ If @ComputerName = $aArray[$i] Then

;~ Local $list = WinList("Shortcut Bar - ")
;~ If $list [0][0] > 1 Then
;~ WinClose("Shortcut Bar - ")
;~ msgbox(0, '', 'You have one instance open')
;~ EndIf
;~ Next

Thanks for the help

Grimm

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites
JLogan3o13

Are you sure you have access to the directory? I just tried it, using both server name and IP address, and it worked just fine.

Edited by JLogan3o13

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

Share this post


Link to post
Share on other sites
BrewManNH

What's the @error returned from the _FIleReadToArray? That will tell you why it didn't read the file.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
grimmlock

BrewManNH,

Error code is 1 is I put the @error just before the For $i = 1 to $aArray[0]

Thanks,

Grimm


Thanks

Grimm

Share this post


Link to post
Share on other sites
grimmlock

JLogan3o13

Yes I have full permissions to the network directory :)

Thanks,

Grimm


Thanks

Grimm

Share this post


Link to post
Share on other sites
kylomas

Put test for @error directly after the filelisttoarray.


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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  

×