Jump to content

Can't FileReadLine from a _RegExport file


Recommended Posts

Hi,

I'm using a _RegExport function that I found on this forum to do a quick check of another user's desktop settings. It basically does a RunAs for that user and dumps some HKCU settings into a textfile. Problem is, when I try to read from the textfile to check some values, I get nada. The file is there and I can open it after the test runs, but during the test if I try a FileRead, I get some gibberish:

ypw (but the y has a horizontal : above it and the p has an extended l going through it)

??

any suggestions?

Thanks!

max

Link to comment
Share on other sites

Maybe unicode format?

Try exporting as "Win9x/NT4"-regfile.

!!!Edit try using in commandline as additional parameter /NT4.

Then the file is exported as 'normal' ANSI-textfile.

Regards

Holger

Edited by Holger
Link to comment
Share on other sites

  • 2 weeks later...

might post the non working script.

<{POST_SNAPBACK}>

Hi,

As requested, below are

1. the function I'm having a problem with getting the FileReadLine to work right. 2. Below this function is the _RegExport function I'm using

3. Below that is a copy of the gibberish I'm seeing in the Log file where I should be seeing text from the textfile:

1. The main function

************************************************************

Func userSystemConfig()

FileWriteLine ( $TestLog, "" & @CRLF)

FileWriteLine ( $TestLog, @TAB & "Running user account configuration tests...")

FileWriteLine ( $TestLog, "" & @CRLF)

FileWriteLine ( $TestLog, "" & @CRLF)

; User RunAsSet along with the _RegExport function to peek at user's HKCU settings

RunAsSet ("user", @Computername, "password")

; dumps the HKCU settings into a separate file and reads them from the file

_RegExport("HKCU\Control Panel\Desktop", "C:\" & "userTest.txt")

RunAsSet()

sleep(2000)

; opens the C:\userTest.txt file and reads the info

$ListUpdateOutput= FileOpen("C:\userTest.txt", 0)

If $ListUpdateOutput = -1 Then

FileWriteLine( $TestLog, "ERROR: Unable to open C:\userTest.txt")

Exit

EndIf

; Here are the lines of information we're extracting from userTest.txt

$anything = FileReadLine ( $ListUpdateOutput, 1)

$screensaveActive = FileReadLine( $ListUpdateOutput, 27)

$wallpaper = FileReadLine( $ListUpdateOutput, 33)

; Test if the ScreenSaver is active

$user_screensaveActive_test = StringMid($screensaveActive, 21, 1)

FileWriteLine( $TestLog, @TAB & "Checking Screen Saver settings: ")

FileWriteLine( $TestLog, "$user_screensaveActive_test: " & $user_screensaveActive_test)

FileWriteLine( $TestLog, "$screensaveActive: " & $screensaveActive)

FileWriteLine( $TestLog, "$anything: " & $anything)

If $user_screensaveActive_test = "0" Then

FileWriteLine( $TestLog, "PASS: user's Screen Saver has been deactivated.")

FileWriteLine( $TestLog, "" & @CRLF)

Else

FileWriteLine( $TestLog, "FAIL: user's Screen Saver has NOT been deactivated!")

FileWriteLine( $TestLog, "" & @CRLF)

EndIf

; Test if wallpaper is installed

$user_wallpaper_test = StringMid($wallpaper, 14, 36)

FileWriteLine( $TestLog, @TAB & "Checking if Wallpaper is installed: ")

FileWriteLine( $TestLog, "$user_wallpaper_test: " & $user_wallpaper_test)

FileWriteLine( $TestLog, "$wallpaper: " & $wallpaper)

If $user_wallpaper_test = "C:\\WINDOWS\\server_wallpaper.bmp" Then

FileWriteLine( $TestLog, "PASS: Server Wallpaper has been installed on user's desktop.")

FileWriteLine( $TestLog, "" & @CRLF)

ElseIf $user_wallpaper_test = "(None) " Then

FileWriteLine( $TestLog, "FAIL: Server Wallpaper has NOT been installed on user's desktop. In fact, user's desktop contains NO wallpaper!")

FileWriteLine( $TestLog, "" & @CRLF)

Else

FileWriteLine( $TestLog, "FAIL: Server Wallpaper has NOT been installed on user's desktop!")

FileWriteLine( $TestLog, "" & @CRLF)

EndIf

; close the userTest.txt file so we can delete it in Cleanup

FileClose($ListUpdateOutput)

FileWriteLine( $TestLog, "" & @CRLF)

FileWriteLine( $TestLog, "------------------")

FileWriteLine ( $TestLog, "" & @CRLF)

EndFunc

*****************************************************

2. the _RegExport function

*********************************

; Here's the RegExport function, which is a wrapper for the REG Export function in Windows

Func _RegExport($sKey2Export, $sWhere2SaveTo)

RunWait(@SystemDir & '\Reg.exe EXPORT "' & $sKey2Export & '" "' & $sWhere2SaveTo & '"', "", @SW_HIDE)

If Not FileExists($sWhere2SaveTo) Then

SetError(1)

Return 0

EndIf

SetError(0)

Return 1

EndFunc ;==>_RegExport

************************************

3. The Logfile results:

********************

------------------

Running user account configuration tests...

screensaveActive2:

Checking Screen Saver settings:

$user_screensaveActive_test:

$screensaveActive:

$anything: ÿþW

FAIL: user's Screen Saver has NOT been deactivated!

Checking if Wallpaper is installed:

$user_wallpaper_test:

$wallpaper:

FAIL: Server Wallpaper has NOT been installed on user's desktop!

------------------

Any suggestions?

Thanks!

max

Link to comment
Share on other sites

Maybe unicode format?

Try exporting as "Win9x/NT4"-regfile.

!!!Edit try using in commandline as additional parameter /NT4.

Then the file is exported as 'normal' ANSI-textfile.

Regards

Holger

<{POST_SNAPBACK}>

Can't seem to find that parameter for the Reg command...

This is a Windows 2003 Server OS.

-max

Link to comment
Share on other sites

@max: did you try it? this parameter is hidden!

RunWait(@SystemDir & '\Reg.exe EXPORT "' & $sKey2Export & '" "' & $sWhere2SaveTo & '" /nt4', "", @SW_HIDE)

<{POST_SNAPBACK}>

The function wasn't working when I added in the parameter. I went forward and used the "type /c inputfile>outputfile" call before I opened the file to read, so it works now.

Thanks for the awesome support!

-max

Link to comment
Share on other sites

The problem is the unicode format.

You have to convert the file or use Holger's method.

If you want to read/write other unicode files too:

RunWait(@ComSpec & " /c type inputfile>outputfile","",@SW_HIDE )

<{POST_SNAPBACK}>

Right on! Got it to work!

Thanks!!!!!

-max

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