mtmartis Posted August 5, 2011 Share Posted August 5, 2011 I am always confused bewtween Dim,local,Global. Basically, I want to run a function that calls a Global variable, but a If-then is used to determine the path of that Global variable. I am guessing even though the global variable gets declared in a If/Then statement, I still can't declare a global variable with the same name twice. And if that is the case, is there a way around this? No matter if the computer name begins with "USA" or not, it always moves the PC to the first $sTargetOU.#include <AD.au3> If StringInStr(@ComputerName,"USA") Then Global $sTargetOU = "OU=1,DC=domain,DC=com" Else Global $sTargetOU = "OU=2,DC=domain,DC=com" EndIf ;Connect to Active Directory _AD_Open() ;Get FQDN of current machine name Global $sObject = _AD_SamAccountNameToFQDN(@ComputerName & "$") ;Move current machine to OU location Global $iValue = _AD_MoveObject($sTargetOU, $sObject) ; Close Connection to the Active Directory _AD_Close()#FYI,he AD functions I am using are by the author, Water, posted here: Link to comment Share on other sites More sharing options...
pieeater Posted August 5, 2011 Share Posted August 5, 2011 using StringCompare() might be what your looking for [spoiler]My UDFs: Login UDF[/spoiler] Link to comment Share on other sites More sharing options...
Scriptonize Posted August 5, 2011 Share Posted August 5, 2011 You should use it like this: #include <AD.au3> Global $sTargetOU, $sObject, $iValue If StringInStr(@ComputerName,"USA") Then $sTargetOU = "OU=1,DC=domain,DC=com" Else $sTargetOU = "OU=2,DC=domain,DC=com" EndIf ;Connect to Active Directory _AD_Open() ;Get FQDN of current machine name $sObject = _AD_SamAccountNameToFQDN(@ComputerName & "{:content:}quot;) ;Move current machine to OU location $iValue = _AD_MoveObject($sTargetOU, $sObject) ; Close Connection to the Active Directory _AD_Close() If you learn from It, it's not a mistake Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 5, 2011 Share Posted August 5, 2011 Your method is awkward, but works fine for me: Global $aStrings[3] = ["USA12345", "12345", "123USA45"] For $n = 0 To UBound($aStrings) - 1 If StringInStr($aStrings[$n], "USA") Then Global $sTargetOU = "OU=1,DC=domain,DC=com" Else Global $sTargetOU = "OU=2,DC=domain,DC=com" EndIf ConsoleWrite($n & ": String = " & $aStrings[$n] & "; $sTargetOU = " & $sTargetOU & @LF) Next This would be a better way to do that check, though: Global $sTargetOU = "OU=1,DC=domain,DC=com" If Not StringInStr(@ComputerName, "USA") Then $sTargetOU = "OU=2,DC=domain,DC=com" Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
mtmartis Posted August 8, 2011 Author Share Posted August 8, 2011 Thanks for the replies, my scripting skills are still pretty raw, it helps to see the proper structure syntax you've all provided. Link to comment Share on other sites More sharing options...
shornw Posted August 8, 2011 Share Posted August 8, 2011 Apologies if this is a stupid question....but can you tell me where the _AD stuff is coming from. I dont have AD.au3 in my include folder either. I am currently using V3.3.6.1, which I believe is the latest version. Thanks [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted August 8, 2011 Share Posted August 8, 2011 Apologies if this is a stupid question....but can you tell me where the _AD stuff is coming from. I dont have AD.au3 in my include folder either. I am currently using V3.3.6.1, which I believe is the latest version.ThanksThere's a link in the first post .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now