header1   header
header
header : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
IMPORTANT: PowerShellCommunity.org is moving! - Wednesday, August 15, 2012

PowerShellCommunity.org is moving!  This community software, and the hardware that it sits on, are no longer serving the purposes of this community.  As a result, we have decided to move this community to a new home at PowerShell.org.  PowerShell.org is already up and running with the new community software and in its new location, so please post any new questions that you have on the forums over there instead of posting them on this site.  We've already started getting some great questions from members of the community over there so please, come on over and join us!

While we are going through this transition, this site will remain up for the short term.  New posts may no longer be created on these forums, however replies to existing posts are allowed so that users who posted questions don't have to re-post the same question on the new site.

[UPDATE 28/02/2013] New user registration has been disabled and forums have now been switched to read-only, including for existing posts since all threads that were started should now be completed. If you have a question about content on this site or about PowerShell in general, head over to PowerShell.org and ask it there where there are people actively using the site and answering questions.

If you have any questions, please let us know on the PowerShell.org site.

Thank you,

Kirk "Poshoholic" Munro

 
Locking/Unlocking Windows 7 Workstations Remotely
Last Post 25 Oct 2012 05:25 PM by TJ. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
CoryGUser is Offline
New Member
New Member
Posts:1
Avatar

--
18 Jun 2012 05:10 PM
    Here's my issue:  I have 9 computers at my desk, mixed between POSIX and windows - I'm also an admin - so when someone pulls me up from my desk I have to lock all the open stations and then unlock them when I get back (typically one at a time as needed).  I've managed to automate the screen locks on all the POSIX boxes with an ssh command and some bash scripts, but I can't figure out how to lock/unlock the windows workstations remotely (they are already logged in, though logging in remotely as a console session would be nice, I don't hold my hopes up for this).

    Is this possible to do through PowerShell or any method short of me writing a c# program that runs constantly on the child machines listening for a command to lock/unlock?  It is only for a single user account, the same user account is being used on the parent machine.

    Any help would be greatly appreciated - thank you for reading :)
    RiffyRiotUser is Offline
    Basic Member
    Basic Member
    Posts:329
    Avatar

    --
    18 Jun 2012 07:04 PM
    Hi,

    The trick is executing this command "rundll32.exe user32.dll,LockWorkStation"

    I tested on Windows 7 Pro and Windows XP Pro.

    If you have Remoting configured and working you can use this...

    invoke-command -computer $computer -scriptblock {start-process 'C:\Windows\System32\rundll32.exe' -ArgumentList 'user32.dll,LockWorkStation'}

    Or, you can go the WMI way...

    $newProc=([WMICLASS]"\\$computer\root\cimv2:win32_Process").Create("C:\Windows\System32\rundll32.exe user32.dll,LockWorkStation")

    As far as unlocking goes, You could use an RDP session with your credentials saved?

    As an admin myself, I don't log into the computer I'm using with my admin credentials. I only use them when required.

    Hope this helps.
    Rule #1: You should only use Format-Table as the final command in the pipeline and only when you're not using the output for anything else
    Dexter34925User is Offline
    New Member
    New Member
    Posts:17
    Avatar

    --
    18 Jun 2012 11:34 PM
    Perfectly explained by RiffyRiot.

    Thanks for sharing
    TJUser is Offline
    New Member
    New Member
    Posts:1
    Avatar

    --
    25 Oct 2012 05:25 PM


    Reboot a computer:
    (gwmi win32_operatingsystem -ComputerName $strComputer).Win32Shutdown(6)

    Shutdown a computer:
    (gwmi win32_operatingsystem -ComputerName $strComputer).Win32Shutdown(12)

    Logoff or Unlock a computer:
    (gwmi win32_operatingsystem -ComputerName $strComputer).Win32Shutdown(0)


    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Many thanks to our original sponsors: Quest Software • SAPIEN Technologies • Compellent • Microsoft footer
    footer   footer