Sign in to follow this  
Followers 0
Docfxit

Trying to kill VNC client on server

5 posts in this topic

When UltraVNC disconnects sometimes the server doesn't remove the client and VNCviewer won't connect again.

If the remote is XP with an WAN IP address I can kill it from the local PC.

If the remote is XP on a lan or it's '98 I'd like to create a way to kill the client.

I'm thinking of running a script on the server that constantly checks for a file on a local server. So if I can't connect to the remote I will be able to delete the file on my local PC so the remote will kill the client.

My first problem is this script isn't finding the file when it really is in the root of C:\

;   Check if it's time to kill VNC

$Name = "RemotePC"
While 1
    If Not FileExists('\\' & $Name & '\C\VNCUp.txt') Then 
        MsgBox(0, "Can't find the file VNCUp.txt", '\\' & $Name & '\C\VNCUp.txt')
        Run("C:\Batch\pskill.exe -t vncviewer.exe", "", @SW_MAXIMIZE)
    EndIf
    Sleep(10000) ;ten seconds
WEnd

Of course any suggestions are welcome and appreciated.

Docfxit

Share this post


Link to post
Share on other sites



me thinks-

$Name = "RemotePC"
While 1
    If Not FileExists('\\' & $Name & '\C$\VNCUp.txt') Then 
        MsgBox(0, "Can't find the file VNCUp.txt", '\\' & $Name & '\C$\VNCUp.txt')
        Run("C:\Batch\pskill.exe -t vncviewer.exe", "", @SW_MAXIMIZE)
    EndIf
    Sleep(10000) ;ten seconds
WEnd

Make sure you got permissions too.

Share this post


Link to post
Share on other sites

Make sure you got permissions too.

Thanks for the reply.

Between the two PC's I'm testing I can read and write files to a different folder. I do have a user signed on with admin rights on both PC's and both users are created on both PC's.

Is there a way I can test the permissions to make sure?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I have changed a bunch on this script. I am currently having two problems that I would like to resolve.

1. When I run it everything runs fine but there is message that goes to the bottom box in Scite that says:

The system cannot find the path specified.

I'd like to know what is causing the message and how to get rid of it. I have tried running it in the debugger but I don't see the message there.

2. The permissions I am giving the file are for Everyone:F. I expected the user Everyone to have full rights to the file. Everyone ends up having no rights to the file. I am running this from a user that has administrator rights.

;   Check if it's time to kill VNC

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;   Warning:    If you run this it will (should) create a file on the PC = $Name
;               This will change permissions on that file with the line with Cacls in it.
;               Make sure you have the password to Administrator just in case the permissions are not set correctly for you.
;               Currently it gives permissions to everyone so it shouldn't give you a problem
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

AutoItSetOption("TrayIconDebug", 1) ;0-off
; Set so that tray displays current line number

$Name = "192.168.1.2"
$Folder = "\Dnload\Delete this to kill the VNCviewer on the remote PC\"
$FileName = "VNCUp.txt"
Global $file

While 1
    If Not FileExists('\\' & $Name & $Folder & $FileName) Then 
        ;MsgBox(0, "Can't find the file VNCUp.txt", '\\' & $Name & $Folder & $FileName)
        Run("C:\Batch\pskill.exe -t vncviewer.exe", "", @SW_MINIMIZE) ; If the file isn't on the remote PC run this on the local PC
        MsgBox(0, "Worked", "Killed VncViewer.exe", 3)
    EndIf

If  Not FileExists('\\' & $Name & $Folder) Then
; Create the folder
    If DirCreate ('\\' & $Name & $Folder) Then
        ; Set super hidden attribute
;        RunWait(@comspec & ' /c attrib +h +s "' & '\\' & $Name & $Folder & "', '', @SW_HIDE)
        ; Set permission if needed (use flag 3 if StdoutRead used also)
        ;MsgBox(0, "Set Permissions", ' /c ' & 'cacls ' & '\\' & $Name & $Folder & ' /e /g '  & "Everyone:F")
        $pid = Run(@comspec & ' /c ' & 'cacls Y:\' & '\\' & $Name & $Folder & ' /t /c /e /g '  & "Everyone:F", '', @SW_HIDE, 1)
        Sleep(1000)
        ; Respond yes to permission prompt
        ;StdInWrite($pid, 'y' & @CRLF)
        ; Check result
        ;$result = StdoutRead($pid)
        ;MsgBox(0x40000, Default, $result, 7)
        ProcessWaitClose($pid)
    EndIf
Endif

If Not FileExists('\\' & $Name & $Folder & $FileName) Then
    ; Create the file
    $file = FileOpen('\\' & $Name & $Folder & $FileName, 10)
    If $file <> -1 Then
        FileWriteLine($file, "Line1")
        FileWriteLine($file, "Line2" & @CRLF)
        FileWriteLine($file, "Line3")
        FileClose($file)
    Else
        MsgBox(0x40030, Default, 'FileOpen error', 3)
    EndIf
EndIf
    Sleep(10000) ;ten seconds
WEnd

Run Instructions: When it runs the first time it creates a folder and a file. To make it re-create the file just delete the folder.

Before I run this the I create the folder C:\Dnload.

This will create a folder with the name "Delete this to kill the VNCviewer on the remote PC" with a file in it.

Thank you,

Docfxit

Edited by docfxit

Share this post


Link to post
Share on other sites

I'd like to find out how I can run the above script over the internet to a remote PC on a LAN. Is there a port that FileExists uses that I could forward. What I have is:

Local PC -> WAN -> Router -> Remote PC

The script runs on the Local PC looking for a file on the remote PC.

Thank you,

Docfxit

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