+ Post New Thread
Results 1 to 10 of 10
Scripts Thread, Script to remotely lock a computer screen in Coding and Web Development; Got this from computerperformance.co.uk ( which I have edited so that it executes rundll32.exe with the relevant parameters.) Code: ' ...
  1. #1

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    7,026
    Thank Post
    1,088
    Thanked 641 Times in 598 Posts
    Rep Power
    209

    Script to remotely lock a computer screen

    Got this from computerperformance.co.uk ( which I have edited so that it executes rundll32.exe with the relevant parameters.)

    Code:
    ' StartProcess.vbs
    ' Sample VBScript to start a process. Inputbox for name
    ' Author Guy Thomas http://computerperformance.co.uk/
    ' Version 2.2 - December 2005
    ' -------------------------------------------------------'
    Option Explicit
    Dim objWMIService, objProcess
    Dim strShell, objProgram, strComputer, strExe, strInput
    strExe = "rundll32.exe user32.dll,LockWorkStation"
    ' Input Box to get name of machine to run the process
    Do
    strComputer = (InputBox(" ComputerName to Run Script",_
    "Computer Name"))
    If strComputer <> "" Then
    strInput = True
    End if
    Loop until strInput = True
    
    ' Connect to WMI
    set objWMIService = getobject("winmgmts://"_
    & strComputer & "/root/cimv2")
    ' Obtain the Win32_Process class of object.
    Set objProcess = objWMIService.Get("Win32_Process")
    Set objProgram = objProcess.Methods_( _
    "Create").InParameters.SpawnInstance_
    objProgram.CommandLine = strExe
    
    'Execute the program now at the command line.
    Set strShell = objWMIService.ExecMethod( _
    "Win32_Process", "Create", objProgram)
    
    'WScript.echo "Created: " & strExe & " on " & strComputer
    WSCript.Quit
    ' End of Example of a Process VBScript
    Was just wondering if anyone could test and confirm if it works or not.

    Should allow you to enter machine name ( possibly ip address of the machine ) and it should lock that computers screen.
    Last edited by mac_shinobi; 5th February 2008 at 04:45 PM.

  2. IDG Tech News

  3. #2

    SYSMAN_MK's Avatar
    Join Date
    Sep 2005
    Location
    Milton Keynes
    Posts
    3,825
    Blog Entries
    2
    Thank Post
    433
    Thanked 1,175 Times in 669 Posts
    Rep Power
    329
    Works a treat here.

  4. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    7,026
    Thank Post
    1,088
    Thanked 641 Times in 598 Posts
    Rep Power
    209
    Cool - cheers for that.

    Just I found this http://www.microsoft.com/technet/scr...4/hey1115.mspx

    And it seemed a lot of work to copy the script from one machine to the next just to lock a screen.

  5. #4
    DSapseid's Avatar
    Join Date
    Feb 2007
    Location
    West Sussex
    Posts
    1,027
    Thank Post
    105
    Thanked 35 Times in 30 Posts
    Rep Power
    22
    Works in XP but doesnt work in Vista

  6. #5

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    11,840
    Blog Entries
    6
    Thank Post
    592
    Thanked 1,043 Times in 920 Posts
    Rep Power
    224
    Nice, i will put that link on the wiki, do you have the full link please?

    Z

  7. #6

    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    4
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Any idea or thoughts on how to get this running on 64bit win7 box?

    Thanks and it works like a charm on 32 bit winXP
    Good work!

  8. #7

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    7,026
    Thank Post
    1,088
    Thanked 641 Times in 598 Posts
    Rep Power
    209
    Possibly the windows firewall or the type of profile you are using on your windows firewall unless you have a software firewall that is blocking it as it relies on wmi

    Also it uses rundll32.exe, does win 7 64 bit have rundll64.exe ??
    Last edited by mac_shinobi; 22nd October 2010 at 09:48 PM.

  9. #8

    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    4
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks for the thoughts I will check into the security settings. We are mostly a XP shop and started to deploy some 7 boxes and was curious how to get it working again. . My thought was that it would no longer be called "Win32_Process" but it looks like this isnt the issue since it is working for you.
    Thanks!

  10. #9

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,039
    Thank Post
    69
    Thanked 275 Times in 218 Posts
    Rep Power
    97
    64bit Windows uses WOW32 to run 32bit processes
    Windows 32bit On Windows 64-bit = It's the (counter-intuitive) WOW64 that runs 32bit.

  11. #10

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    7,026
    Thank Post
    1,088
    Thanked 641 Times in 598 Posts
    Rep Power
    209
    Quote Originally Posted by bheisler View Post
    Any idea or thoughts on how to get this running on 64bit win7 box?

    Thanks and it works like a charm on 32 bit winXP
    Good work!
    As in locally on your own computer or remotely from another win 7 64 bit machine or what exactly ?

    The other thing I was not 100% sure on was if it required the full path to the rundll32.exe but in the script I just executed rundll32.exe without a fully qualified path ie

    strExe = "notepad.exe"

    versus

    strExe = "c:\windows\notepad.exe"

    Just an example as I am not sure where notepad is located but that is neither here or there seeing as it is the rundll exe that I assume that needs to execute the lock work station command - unless there is another way of locking a remote work station that does not require wmi which may be more secure ??
    Last edited by mac_shinobi; 23rd October 2010 at 05:05 AM.

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 7
    Last Post: 30th December 2007, 01:43 PM
  2. Replies: 7
    Last Post: 14th December 2007, 11:38 AM
  3. Replies: 10
    Last Post: 26th June 2007, 07:50 AM
  4. auto lock computer after set time
    By timbo343 in forum Windows
    Replies: 13
    Last Post: 30th March 2007, 07:54 AM
  5. Replies: 21
    Last Post: 11th July 2006, 07:37 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •