Sign in to follow this  
Followers 0
zore

Quick question about while command

5 posts in this topic

I'm building a script that will install and msi (this works) and create a directory in the logged on users My Documents directory. OS is windows 7 and I'm using sccm to deploy the package. The script seems to work if you double click the exe but fails when run thru sccm with admin rights. The user base will all be regular users with out admin rights. The reason for the while and reading from txt to get dir name is that sometimes windows will create a user profile that will be username.domain if the username already exists.

$var1 = RegRead ("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI", "LastLoggedOnSAMUser")

$file2 = FileOpen ("C:\IronmountainInst.txt", 1)

;if FileExists ("C:\Program Files (x86)\Iron Mountain\Connected BackupPC") Then

;Exit

;Else

fileWriteLine ($file2, "Var1="& $var1)

$var2 = StringTrimLeft ( $var1 , 6 )

fileWriteLine ($file2, "Var2="& $var2)

;FileInstall ("C:\Users\volltrauerj\Documents\07.Wise Scripts\Iron Mountain\Iron Mountain\Production AgentSetupMSI\Agentsetup.msi", @TempDir & "\AgentSetup.msi")

;RunWait ("C:\Windows\System32\MSIexec /qn /i" & @TempDir & "\AgentSetup.msi LDAPID=" & $var2 & " FIRSTBACKUP=0 MAKESHORTCUT=0")

;FileDelete ( @TempDir & "\AgentSetup.msi")

;Get all users profiles

RunWait ("C:\Windows\System32\cmd.exe /c dir /b C:\Users > C:\profiles.txt")

;Create NoBackupDir

$file = FileOpen ( "C:\profiles.txt",0)

;Failes after here. As $var3 is never written to text.

While 1

$name1=FileReadLine($file)

If StringRegExp ($name1, $var2) = 1 Then ExitLoop; end of file

WEnd

fileWriteLine ($file2, "Var3="& $name1)

DirCreate ("C:\Users\turnerj\documents\NoBackup")

FileClose($file)

FileClose($file2)

;Else

;EndIf

As you can see, I commented out some of the script as that works. Is there a better way of doing this?

Share this post


Link to post
Share on other sites



Hope this is easier to read.

PHByZSBjbGFzcz0iX3ByZXR0eVhwcmludCI+JHRleHQ9J10kdmFyMSA9IFJlZ1JlYWQgKCZxdW90O0hLRVlfTE9DQUxfTUFDSElORTY0XFNPR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7ICZxdW90O1xBZ2VudFNldHVwLm1zaSZxdW90OykKCgo7R2V0IGFsbCB1c2VycyBwcm9maWxlcwpSdW5XYWl0ICgmcXVvdDtDOlxXaW5kb3dzXFN5c3RlbTMyXGNtZC5leGUgL2MgZGlyIC9iIEM6XFVzZXJzICZndDsgQzpccHJvZmlsZXMudHh0JnF1b3Q7KQoKO0NyZWF0ZSBOb0JhY2t1cERpcgokZmlsZSA9IEZpbGVPcGVuICggJnF1b3Q7QzpccHJvZmlsZXMudHh0JnF1b3Q7LDApCldoaWxlIDEKICAkbmFtZTE9RmlsZVJlYWRMaW5lKCRmaWxlKQogIElmIFN0cmluZ1JlZ0V4cCAoJG5hbWUxLCAgJHZhcjIpID0gMSBUaGVuIEV4aXRMb29wOyBlbmQgb2YgZmlsZQoKV0VuZAoKZmlsZVdyaXRlTGluZSAoJGZpbGUyLCAmcXVvdDtWYXIzPSZxdW90OyZhbXA7ICRuYW1lMSkKCgpEaXJDcmVhdGUgKCZxdW90O0M6XFVzZXJzXHR1cm5lcmpcZG9jdW1lbnRzXE5vQmFja3VwJnF1b3Q7KQoKCkZpbGVDbG9zZSgkZmlsZSkKRmlsZUNsb3NlKCRmaWxlMikKO0Vsc2UKO0VuZElmPC9wcmU+[/__PRE_PROTECTED]

Share this post


Link to post
Share on other sites

I figured it out as a case sensativity problem. I just have to figure out how to make the If StringRegExp ($name1, $var2) = 1 Then ExitLoop not case sensative. I believe it's ?i but i just have to figure out syntax.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The syntax with StringRegExp is like so: (?i)case-insensitive-pattern-here.

Are you sure you need StringRegExp? StringInStr can tell you in string B is container in string A and it has a simple option for case-sensitivity. By default it is not case sensitive.

Edited by Manadar

Share this post


Link to post
Share on other sites

The syntax with StringRegExp is like so: (?i)case-insensitive-pattern-here.

Are you sure you need StringRegExp? StringInStr can tell you in string B is container in string A and it has a simple option for case-sensitivity. By default it is not case sensitive.

Thanks for the info. The entire code i created from googling bits of it since I'm a total nub at this. I was able to get the installation to work once I added a bit of code for case insensitivity.

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