Announcement

Collapse
No announcement yet.

Script for Remote Desktop

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script for Remote Desktop

    Masters & Friends,

    I am developing a web based software for Remote Control. I can do this from VNC and VBScript. If I hardcode the client's IP in VBScript I am able to get Remote Desktop.
    But What I want to do is that,
    In a text box i will enter the client's hostname.
    Script will search the host.
    Then It will copy 2 files of TightVNC. One is DLL another is EXE.
    Start the VNC service,
    then open browser window of remote desktop.

    I am able to copy the 2 files to specified PC, but i am not able to start the VNC service on the remote PC. I think it s the problem of registry entry of the service.

    I have tried by SC command also but it is not solving the problem.

    Can anybody help me in this ?
    How to start a service on a remote PC ?
    From,
    Amit
    [/EMAIL]

  • #2
    Re: Script for Remote Desktop

    Haha, that's two in one day.

    I've also been asked if I can make someone's life easier by copying a file to a machine, scheduling a task and starting the task service.

    So far I have everything working apart from the service start/restart.
    Will let you know when I have something...

    Code:
    strComputer = InputBox("Which Computer?","Which Computer do you want to break today?","?")
    strService = InputBox("Which Service are you breaking today?","Start Service","Schedule")
    
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='" & strService & "'")
    For each objService in colServiceList
        errReturn = objService.StartService()
    Next
    Wscript.Sleep 20000
    Set colServiceList = objWMIService.ExecQuery("Associators of " _
       & "{Win32_Service.Name='" & strService & "'} Where " _
            & "AssocClass=Win32_DependentService " & "Role=Dependent" )
    For each objService in colServiceList
        objService.StartService()
    Next
    If it is always going to be the same service change the second input box - it'd be a pain otherwise;

    (get the service name from services double click the service and it'll give u the service name (not display name)

    Code:
    strComputer = InputBox("Which Computer?","Which Computer do you want to break today?","?")
    strService = "VNCService"
    
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='" & strService & "'")
    For each objService in colServiceList
        errReturn = objService.StartService()
    Next
    Wscript.Sleep 20000
    Set colServiceList = objWMIService.ExecQuery("Associators of " _
       & "{Win32_Service.Name='" & strService & "'} Where " _
            & "AssocClass=Win32_DependentService " & "Role=Dependent" )
    For each objService in colServiceList
        objService.StartService()
    Next
    Last edited by Lan; 8th August 2007, 15:20. Reason: adding and fixing typos etc.
    This is my signature.

    Comment


    • #3
      Re: Script for Remote Desktop

      Use psexec.exe...you can run the "sc" command using that:

      Set objShell = CreateObject("WScript.Shell")
      objShell.Run "%comspec% /C psexec.exe \\" & strComputer &" sc start ""vncservice""", 0
      Psexec.exe has to be in the same directory as the script. Whatever the vnc service name is, replace it for what I have in there. Try that and see if it works...

      Comment


      • #4
        Re: Script for Remote Desktop

        try downloading the script from here, I have been using it for some years with great success, you can shell out to dos from vbscript to call it if need be - or you might just find the clues you need in his code

        http://www.darkage.co.uk/faq/index.htm#whatfp

        Comment


        • #5
          Re: Script for Remote Desktop

          Originally posted by amit View Post
          I am developing a web based software for Remote Control. I can do this from VNC and VBScript. If I hardcode the client's IP in VBScript I am able to get Remote Desktop.
          But What I want to do is that,
          In a text box i will enter the client's hostname.
          Script will search the host.
          Then It will copy 2 files of TightVNC. One is DLL another is EXE.
          Start the VNC service,
          then open browser window of remote desktop.
          Don't know the name of the VNC service - that'll need fixing
          ...and the filenames and locations of them.
          Don't know about the browser window of remote desktop either... Browser window of RDC?

          Code:
          ' Deployment  + Service Start
          ' Lan
          ' http://forums.petri.com/showthread.php?p=76949#post76949
          
          
          ' Copy strings
          strAsst = InputBox("Please enter the computer name:","Deployment+VNC Service Starter","?")
          strService = "VNC"
          
          WScript.echo "Copying files - This make take a few minutes. " & VBNewLine & "Script will resume when this is complete.  Please be patient."
          
          ' Location of Files to copy
          strLocDll = "c:\somewhere\"
          strLocExe = "c:\somewhere\"
          strFileDll = "dll.dll"
          strFileExe = "exe.exe"
          
          
          Dim FileSystemObject1
          
          Set FileSystemObject1 = CreateObject("Scripting.FileSystemObject")
            FileSystemObject1.CopyFile strLocDll & strFileDLL, "\\" & strAsst & "\c$\" & strFileDll
          Set FileSystemObject1 = nothing
          
          Dim FileSystemObject2
          
          Set FileSystemObject2 = CreateObject("Scripting.FileSystemObject")
            FileSystemObject2.CopyFile strLocExe & strFileExe, "\\" & strAsst & "\c$\" & strFileExe
          Set FileSystemObject2 = nothing
          
          ' Start VNC Service
            Set objWMIService = GetObject("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" & strAsst & "\root\cimv2")
            Set colServiceList = objWMIService.ExecQuery _
                ("Select * from Win32_Service where Name='" & strService & "'")
            For each objService in colServiceList
                errReturn = objService.StartService()
            Next
            Wscript.Sleep 20000
            Set colServiceList = objWMIService.ExecQuery("Associators of " _
              & "{Win32_Service.Name='" & strService & "'} Where " _
                    & "AssocClass=Win32_DependentService " & "Role=Dependent" )
            For each objService in colServiceList
                objService.StartService()
            Next
          
          ' Copy and Service Complete, wait for script to continue
            WScript.echo "Files has been copied to " & strAsst & VBNewLine & strService & " Service has been Started." & VBNewLine & "Click OK to continue."
          
          ' Open Browser window of Remote Desktop
          ' I don't know exactly what you want to do here...
          Last edited by Lan; 9th August 2007, 12:13. Reason: adding stuff
          This is my signature.

          Comment


          • #6
            Re: Script for Remote Desktop

            Thanks a lot Guys for replies to my questions.
            I am not getting time for testing because I am out of station for a week, but I will reply back surely to your posts.

            Thanks again.

            Amit
            From,
            Amit
            [/EMAIL]

            Comment

            Working...
            X