Sign in to follow this  
Followers 0
Bradman

Network Path....Read From Text File

4 posts in this topic

I need some helpplease. I have this script that reads from a text file that has computer names along with the path, line by line.

For example:

Line 1 "C:\SCRIPTS\delprof.exe /C:\\PCNAME-XXXX-01 /P "

Line 2 "C:\SCRIPTS\delprof.exe /C:\\PCNAME-XXXX-02 /P "

This will give me a grand total of 21 systems on 21 lines in the text file.

The script works just fine when it reads a local path such as.

Line 1 C:\SCRIPTS\delprof.exe

Line 2 C:\SCRIPTS\delprof.exe

Ect.

I keep getting an error that says the parameter is wrong on line.18 the Run($line) command when I switch to the network paths.

"C:\SCRIPTS\delprof.exe /C:\\PCNAME-XXXX-01 /P " works fine when it is NOT read from the text file.

I am not sure what to do at this point. You will have to forgive my ignorance. I have never done any programming or scripting until just 6 weeks ago.

I have tried everything I know (limited knowledge). I would appreciate some help or direction.

Thanks,

Bradman the NOOB

Below is my code.

CODE

$g_szVersion = "My Script 1.1"

If WinExists($g_szVersion) Then Exit

AutoItWinSetTitle($g_szVersion)

Opt("WinWaitDelay",250)

Opt("WinTitleMatchMode",4)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)

Opt("RunErrorsFatal", 0)

#include <Date.au3>

HotKeySet("^!x", "MyExit")

RunAsSet("XXXXX", "XX", "XXXXXXXXX",2)

$file = FileOpen("C:\SCRIPTS\SYS_NAMES.txt", 0); text file has the delprof.exe path ie "C:\SCRIPTS\Delprof.exe" local for the test

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

If @error = -1 Then MsgBox(16, 'WARNING', 'UNABLE TO READ FILE OR END OF FILE!',5)

Sleep(1000)

Run($line)

If @error Then MsgBox(16, 'WARNING', 'DELPROF.EXE DID NOT RUN!',5)

WinActivate("C:\SCRIPTS\Delprof.exe","")

WinWaitActive("C:\SCRIPTS\Delprof.exe","",8)

Sleep(1000)

Send("Y")

Sleep(1000)

Send("{ENTER}")

If ProcessExists("delprof.exe") Then ProcessWaitClose("delprof.exe")

If @ERROR Then

$file = FileOpen("C:\SCRIPTS\DELETE_PROFILE_LOG.txt", 9)

FileWrite($file,"UNABLE TO ACCESS REMOTE SYSTEM: ")

FileWrite($file,$line & @CRLF)

FileWrite($file, (_NowDate()) & @CRLF)

FileWrite($file, (_NowtIME(3)) & @CRLF)

FileWrite($file, " " & @CRLF)

FileClose($file)

EndIf

Wend

MsgBox(32, 'SYSTEMS LIST COMPLETE!', ' ALL SYSTEMS ON LIST PROCESSED! ATTEMPTED DELETION OF PROFILES COMPLETE!'); I use this message box as a way of controlling the test when the loop is running!

FileClose($file)

RunAsSet()

Func MyExit()

Exit

EndFunc

Share this post


Link to post
Share on other sites



Not sure. Perhaps your RunAsSet is failing?

Returns 1--regardless of success. (If the login information was invalid, subsequent Run/RunWait commands will fail....)

With some changes that may help with the script in general.

CODE
$g_szVersion = "My Script 1.1"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)
Opt("WinWaitDelay", 250)
Opt("WinTitleMatchMode", 4)
Opt("WinDetectHiddenText", 1)
Opt("MouseCoordMode", 0)
Opt("RunErrorsFatal", 0)
#include <Date.au3>

HotKeySet("^!x", "MyExit")

RunAsSet("XXXXX", "XX", "XXXXXXXXX", 2)
if Not IsAdmin() Then
    MsgBox(0, @UserName, 'You are not an admin', 5)
EndIf

$file = FileOpen("C:\SCRIPTS\SYS_NAMES.txt", 0); text file has the delprof.exe path ie "C:\SCRIPTS\Delprof.exe" local for the test
If $file <> -1 Then
    While 1
        $line = FileReadLine($file)
        If @error = -1 Then
            MsgBox(16, 'WARNING', 'UNABLE TO READ FILE OR END OF FILE!', 5)
            ExitLoop
        EndIf
        Sleep(1000)
        Run($line)
        If @error Then
            MsgBox(16, 'WARNING', 'DELPROF.EXE DID NOT RUN!', 5)
            MsgBox(16, 'Command used:', $line, 5)
            ContinueLoop
        EndIf
        WinActivate("C:\SCRIPTS\Delprof.exe")
        WinWaitActive("C:\SCRIPTS\Delprof.exe", "", 8)
        Sleep(1000)
        Send("Y")
        Sleep(1000)
        Send("{ENTER}")
        If ProcessExists("delprof.exe") Then ProcessWaitClose("delprof.exe")
        If @error Then ; @error from what source?
            $file = FileOpen("C:\SCRIPTS\DELETE_PROFILE_LOG.txt", 9)
            FileWrite($file, "UNABLE TO ACCESS REMOTE SYSTEM: ")
            FileWrite($file, $line & @CRLF)
            FileWrite($file, (_NowDate()) & @CRLF)
            FileWrite($file, (_NowTime(3)) & @CRLF)
            FileWrite($file, " " & @CRLF)
            FileClose($file)
        EndIf
    WEnd
    ;
    MsgBox(32, 'SYSTEMS LIST COMPLETE!', ' ALL SYSTEMS ON LIST PROCESSED! ATTEMPTED DELETION OF PROFILES COMPLETE!'); I use this message box as a way of controlling the test when the loop is running!
    FileClose($file)
Else
    MsgBox(16, 'Error', 'FileOpen error', 5)
EndIf

RunAsSet()

Func MyExit()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

I am not sure if it is the Runas.....I can get a single system / path to work but not able to get the script to read from the file when using the network paths.

I have gotten the local path to read fine from the file.

I will try your changes at work in the morning and post a reply.

TY

Bradman

Share this post


Link to post
Share on other sites

MHz

Same thing, the Runasset works fine, as does the Isadmin. I still get an error on the Run($line) cmd. I am not sure if it is syntax related or something else.

TY for checking it out!

I will play around with the script some more today at work.

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