none
Can you add a RunOnce per user through an MDT TS? RRS feed

  • Question

  • I have a vbs that works to do what I need it to. However, it needs to run one time, for each user who signs onto a pc.

    I read some on RunOnce but I don't know how to configure that in a Task Sequence.

    I'm maybe thinking of importing the RunOnce (running the VBS) to the registry on target machines? But then that means I have to copy over the VBS in a step as well.
    Just looking for ideas on running this VBS once per user.
    Thanks

    Saturday, May 5, 2018 8:56 PM

Answers

  • Sure. Here is how I approach this - there may be a more elegant solution, but this one works for me:

    Create a batch file with the following content:

    reg load "hku\Default" "C:\USers\Default\NTUSER.DAT"
    reg import %~dp0runonce.reg
    reg unload "hku\default"
    

    Create a runonce.reg file in the same folder with the following content. Adjust the command you want to run:

    Windows Registry Editor Version 5.00
    
    [HKEY_USERS\Default\Software\Microsoft\Windows\CurrentVersion\Runonce]
    "Logon"="Powershell.exe -NoProfile -ExecutionPolicy ByPass -WindowStyle Hidden -file C:\\FinalConfig\\Logon.ps1"
    
    [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce]
    "Logon"="Powershell.exe -NoProfile -ExecutionPolicy ByPass -WindowStyle Hidden -file C:\\FinalConfig\\Logon.ps1"

    Now, your mileage with enabling NumLock on startup may vary: according to a number of articles I read last week, Windows 10 will disable NumLock during startup


    Cheers,
    Anton

    Vacuum Breather Blog | Wing Commander Saga | Twitter

    Note: Posts are provided "AS IS" without warranty of any kind. If posts are helpful please don't forget to rate them as "Helpful" or as "Answer".

    • Marked as answer by the1rickster Thursday, May 10, 2018 2:07 PM
    Monday, May 7, 2018 7:21 AM

All replies

  • What I have found today so far...

    If I load the .default registry hive and change the RunOnce, running a vbs I need, it works. However, I only need this to run on Panasonic models. It's likely not a huge deal than what I'm making it...it's merely to turn off Numlock for each user. The issue from Panasonic was, the script they gave me runs EVERY time every user signs on, so every-other login switches the value. I have:

    Set WshShell=CreateObject("Wscript.Shell")
    WshShell.SendKeys "{NUMLOCK}"

    and this toggles between each logon. Then there's:

    [HKEY_USERS\.DEFAULT\Control Panel\Keyboard] “InitialKeyboardIndicators”=”0” that I use as reg add and it seems to change the value but not the result when logged on. I'm just hoping for something to run one time, for each new user. What I see online is that RunOnce kept deleting itself from the registry until I loaded the hive.
    Any suggestions would be great.

    Sunday, May 6, 2018 5:38 PM
  • Sure. Here is how I approach this - there may be a more elegant solution, but this one works for me:

    Create a batch file with the following content:

    reg load "hku\Default" "C:\USers\Default\NTUSER.DAT"
    reg import %~dp0runonce.reg
    reg unload "hku\default"
    

    Create a runonce.reg file in the same folder with the following content. Adjust the command you want to run:

    Windows Registry Editor Version 5.00
    
    [HKEY_USERS\Default\Software\Microsoft\Windows\CurrentVersion\Runonce]
    "Logon"="Powershell.exe -NoProfile -ExecutionPolicy ByPass -WindowStyle Hidden -file C:\\FinalConfig\\Logon.ps1"
    
    [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce]
    "Logon"="Powershell.exe -NoProfile -ExecutionPolicy ByPass -WindowStyle Hidden -file C:\\FinalConfig\\Logon.ps1"

    Now, your mileage with enabling NumLock on startup may vary: according to a number of articles I read last week, Windows 10 will disable NumLock during startup


    Cheers,
    Anton

    Vacuum Breather Blog | Wing Commander Saga | Twitter

    Note: Posts are provided "AS IS" without warranty of any kind. If posts are helpful please don't forget to rate them as "Helpful" or as "Answer".

    • Marked as answer by the1rickster Thursday, May 10, 2018 2:07 PM
    Monday, May 7, 2018 7:21 AM
  • Thanks. I'll give this a go today. What I'm unclear of is the PS. I have a vbs so how/where would I incorporate that into the RunOnce? Would this be my PS:
    Set WshShell=CreateObject("Wscript.Shell")
    WshShell.SendKeys "{NUMLOCK}"

    What I get running that in PS is that it says WshShell is not recognized, so I went with vbs. Just double-clicking on it does toggle the numlock on/off.

    Wednesday, May 9, 2018 12:30 PM
  • If you were to use vbs replace the command between the quotation marks with something along the lines of cscript.exe %path to your vbs%

    Cheers,
    Anton

    Vacuum Breather Blog | Wing Commander Saga | Twitter

    Note: Posts are provided "AS IS" without warranty of any kind. If posts are helpful please don't forget to rate them as "Helpful" or as "Answer".

    Wednesday, May 9, 2018 12:32 PM
  • Something like this?:

    Windows Registry Editor Version 5.00

    [HKEY_USERS\Default\Software\Microsoft\Windows\CurrentVersion\Runonce]
    "Logon"="cscript.exe c:\numlock.vbs"

    [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce]
    "Logon"="cscript.exe c:\numlock.vbs"

    If I place the vbs in my main mdtserver\share folder, what's the proper way to reference that location?

    Wednesday, May 9, 2018 12:43 PM
  • For some reason, the RunOnce key is not showing up in the registry. Here's all I'm using:

    a reg I made in Notepad....

    Windows Registry Editor Version 5.00

    [HKEY_USERS\Default\Software\Microsoft\Windows\CurrentVersion\Runonce]
    "Logon"="cscript.exe \\mdtserver\share\NumlockPan\numlock.vbs"

    [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce]
    "Logon"="cscript.exe \\mdtserver\share\NumlockPan\numlock.vbs"

    a batch file:
    reg load "hku\Default" "C:\Users\Default\NTUSER.DAT"
    reg import %~dp0runonce.reg
    reg unload "hku\default"

    and the vbs:
    Set WshShell=CreateObject("Wscript.Shell")
    WshShell.SendKeys "{NUMLOCK}"

    I just don't see the RunOnce key in the registry so it's not being created.

    Wednesday, May 9, 2018 1:31 PM
  • Can you import your reg file manually? If not, then it is a reg file issue. If you can, then we need to investigate further.

    Cheers,
    Anton

    Vacuum Breather Blog | Wing Commander Saga | Twitter

    Note: Posts are provided "AS IS" without warranty of any kind. If posts are helpful please don't forget to rate them as "Helpful" or as "Answer".

    Wednesday, May 9, 2018 2:26 PM
  • I'm going to try having MDT copy both the reg file and vbs to the C:Windows of the target pc and run the reg file as

    Windows Registry Editor Version 5.00

    [HKEY_USERS\Default\Software\Microsoft\Windows\CurrentVersion\Runonce]
    "Logon"="cscript.exe C:\Windows\numlock.vbs"

    [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce]
    "Logon"="cscript.exe C:\Windows\numlock.vbs"

    We'll see how that does. MDT finishes with zero errors but it does not create the registry entry.

    Wednesday, May 9, 2018 2:29 PM
  • The thing is: error handling in batch files is somewhat rudimentary which explains MDT‘s behavior.

    Cheers,
    Anton

    Vacuum Breather Blog | Wing Commander Saga | Twitter

    Note: Posts are provided "AS IS" without warranty of any kind. If posts are helpful please don't forget to rate them as "Helpful" or as "Answer".

    Wednesday, May 9, 2018 2:33 PM
  • If I copy the vbs, batch and reg files to C:\Windows of a physical pc, and run the batch, I see in the HKCU path, a RunOnce key, but it lists as Default, REG-SZ and value not set under Data.
    Wednesday, May 9, 2018 2:54 PM
  • Is the "logon" = "script.exe C:\Windows\numlock.vbs" correct format for vbs as opposed to having used a PS instead? Would I perhaps need  something similar to 'reg add' where I have to specify the key, type, value, etc?
    Wednesday, May 9, 2018 3:00 PM
  • As I already mentioned above, try importing your reg file manually in an effort to narrow down the cause for why it is not working (from my own use cases I know it should). If it does not set correct values, then you will need to recreate your reg file (ideally by setting the RunOnce key in current user context manually, exporting the reg file and then adding the default user part). You could also use this script from TechNet gallery as your template - basically it does everything I outlined above.

    Cheers,
    Anton

    Vacuum Breather Blog | Wing Commander Saga | Twitter

    Note: Posts are provided "AS IS" without warranty of any kind. If posts are helpful please don't forget to rate them as "Helpful" or as "Answer".

    Wednesday, May 9, 2018 3:31 PM
  • Guess I have free time for this again.....
    DO all three files have to exist on the target pc? The vbs, the batch file and the reg file?

    I see you said that the batch and reg must be in the same location.
    If I run the batch on the target pc desktop, it will work. I had MDT copy the vbs and reg file to C:\Windows and had the reg file say:

    c:\\windows\\numlock.vbs

    Only running it on the target pc will get it to work. MDT isn't yet.

    Wednesday, May 9, 2018 6:58 PM
  • I am copying everything to local hard drive, but it should work when being executed from your deployment share as well. Only your vbs file should be copied down to target machine.

    Cheers,
    Anton

    Vacuum Breather Blog | Wing Commander Saga | Twitter

    Note: Posts are provided "AS IS" without warranty of any kind. If posts are helpful please don't forget to rate them as "Helpful" or as "Answer".

    Wednesday, May 9, 2018 7:03 PM
  • If you copy everything to C: then how do you kick off the bat file in MDT?
    Wednesday, May 9, 2018 7:46 PM
  • I got it to work this way, which is essentially the way you suggested:

    Copied the vbs file to C:\Windows
    Copied the runonce.reg to C:\Windows
    And ran the batch as an app

    My runonce for USERS and CU is
    "Logon"="cscript.exe c:\\windows\\numlock.vbs"   and

    batch file is
    reg import "C:\Windows\runonce.reg"

    I have no idea how it became to involving. It should have worked all along but perhaps there are
    permissions issues. It's finally working correctly, once per user. (even as admin!).

    Thanks so much!


    Oddly, when these Panasonic Toughbooks boot up, the numlock is off until the moment you log on, then it turns on, so this is really helpful. There is no side number pad, so when you start typing, it's mostly all jibberish.
    Thursday, May 10, 2018 2:06 PM
  • It is one of those things... I am glad you got it working.

    Cheers,
    Anton

    Vacuum Breather Blog | Wing Commander Saga | Twitter

    Note: Posts are provided "AS IS" without warranty of any kind. If posts are helpful please don't forget to rate them as "Helpful" or as "Answer".

    Thursday, May 10, 2018 4:40 PM