+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
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
    9,993
    Thank Post
    3,539
    Thanked 1,110 Times in 1,016 Posts
    Rep Power
    374

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

    SYSMAN_MK's Avatar
    Join Date
    Sep 2005
    Posts
    4,009
    Thank Post
    490
    Thanked 1,345 Times in 731 Posts
    Rep Power
    429
    Works a treat here.

  3. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,993
    Thank Post
    3,539
    Thanked 1,110 Times in 1,016 Posts
    Rep Power
    374
    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.

  4. #4
    DSapseid's Avatar
    Join Date
    Feb 2007
    Location
    West Sussex
    Posts
    1,154
    Thank Post
    130
    Thanked 54 Times in 47 Posts
    Rep Power
    38
    Works in XP but doesnt work in Vista

  5. #5

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,323
    Thank Post
    903
    Thanked 1,802 Times in 1,551 Posts
    Blog Entries
    12
    Rep Power
    467
    Nice, i will put that link on the wiki, do you have the full link please?

    Z

  6. #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!

  7. #7

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,993
    Thank Post
    3,539
    Thanked 1,110 Times in 1,016 Posts
    Rep Power
    374
    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 10:48 PM.

  8. #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!

  9. #9

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

  10. #10

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,993
    Thank Post
    3,539
    Thanked 1,110 Times in 1,016 Posts
    Rep Power
    374
    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 06:05 AM.

  11. #11

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,993
    Thank Post
    3,539
    Thanked 1,110 Times in 1,016 Posts
    Rep Power
    374
    @Steve21 - what would I have to do to get this to work on windows 7 ?

    I did try and execute a command prompt using a domain admin account, drag and drop script onto said command prompt and execute this way but get the same error

  12. #12

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,772
    Thank Post
    354
    Thanked 533 Times in 498 Posts
    Rep Power
    182
    Quote Originally Posted by mac_shinobi View Post
    @Steve21 - what would I have to do to get this to work on windows 7 ?

    I did try and execute a command prompt using a domain admin account, drag and drop script onto said command prompt and execute this way but get the same error
    What error are you getting?

    *Edit - Just checked above script better, It won't work on Vista or above due to session isolation again. You're trying to run an exe within another users session (session 0/1 isolation blahblah). Unless you impersonate user and run as them it won't work by default at all.

    Steve
    Last edited by Steve21; 21st August 2012 at 07:00 PM.

  13. #13

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,314
    Thank Post
    13
    Thanked 237 Times in 225 Posts
    Rep Power
    69
    Run it on my home pc using localhost as target and it worked, will have a bit of fun with this at work tomorrow

  14. #14

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,772
    Thank Post
    354
    Thanked 533 Times in 498 Posts
    Rep Power
    182
    Quote Originally Posted by MatthewL View Post
    Run it on my home pc using localhost as target and it worked, will have a bit of fun with this at work tomorrow
    If you're using 7 at school most likely won't work (won't swear it, but 99%), Running it locally is within same session, remotely isnt

    Steve

  15. #15

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,993
    Thank Post
    3,539
    Thanked 1,110 Times in 1,016 Posts
    Rep Power
    374
    Quote Originally Posted by Steve21 View Post
    What error are you getting?

    *Edit - Just checked above script better, It won't work on Vista or above due to session isolation again. You're trying to run an exe within another users session (session 0/1 isolation blahblah). Unless you impersonate user and run as them it won't work by default at all.

    Steve
    1. GetObject error - access denied ( doesn't matter how I execute the vbscript ie from a command prompt with domain admin elevated access rights --> cd to directory --> name.vbs --> press enter )
    2. how do I make it run in the same session as the remote user ?
    3. When googling there was a reg key that you can apparently change or adjust and a couple of other things but didn't get around to trying it

    Thanks



SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

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, 08:50 AM
  4. auto lock computer after set time
    By timbo343 in forum Windows
    Replies: 13
    Last Post: 30th March 2007, 08:54 AM
  5. Replies: 21
    Last Post: 11th July 2006, 08: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
  •