Batch file that runs once for all new user accounts


  1. Posts : 34
    Windows 10 Pro x64
       #1

    Batch file that runs once for all new user accounts


    Hey guys i need some help. I have an app called StartIsBack that i installed on our school computers. I want to do 2 things. First i want to add a registry key to the hkey current user key that copies the customized start menu settings when the user first logs on silently and then restarts windows explorer. I want to set the batch file to delete after the key is installed. Any help on this would be greatly appreciated. I couldnt get sysprep copyprofile to work with my image so i am trying to find a different method of doing this. Thanks so much!
      My Computer


  2. Posts : 16,712
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #2

    1 You can use the Reg command to do the Registry work - you can find out how to use it by entering reg /? in a command window.
    2 You can restart Windows explorer using the guidance in Option 2 of How to Restart explorer.exe Process in Windows 10
    3 You can get the batch file to delete itself by putting a del command on the last line of the batch file.
      My Computer


  3. Posts : 17,661
    Windows 10 Pro
       #3

    afdude08 said:
    I couldnt get sysprep copyprofile to work with my image so i am trying to find a different method of doing this.
    What was the issue with Sysprep? Maybe we could help you finding a solution for that.

    I'm asking because the easiest and recommend way to do this is to do it in Audit Mode, Sysprep with CopyProfile set to TRUE. Open Notepad, type your commands and add del %0 as last command line. That takes care of deleting the batch when it's run. Save the file as a .bat in %appdata%\Microsoft\Windows\Start Menu\Programs\Startup.

    I usually name these batches I want to be run only once whenever a new user signs in first time as RunOnce.bat.

    When done, run Sysprep. Remember that for CopyProfile to work you must use the /generalize switch with Sysprep command, for instance to run Sysprep and shutdown to be able to capture the Windows image, you would use the following command:

    %windir%\system32\sysprep\sysprep.exe /generalize /oobe /unattend:W:\YourAnswerFile.xml

    /unattend:AnswerFilePathAndName.xml is optional; if you save the answer file as unattend.xml in C:\Windows\System32\Sysprep folder, it will be automatically used. If you name the answer file to something else, or save it to another location, use /unattend switch.

    That's it.

    I'll add a sample RunOnce.bat below, you can just copy and modify it according to your needs. This sample batch would set screensaver active (enabled) setting the value of string (REG_SZ) ScreenSaveActive to 1, and force user to enter password when resumed from screensaver by setting the value of string ScreenSaverIsSecure to 1. Both strings are in key HKEY_CURRENT_USER\Control Panel\Desktop. When new user signs in first time, the batch will be run and deleted so it only runs once for each new user:

    Code:
    reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /d "1" /t REG_SZ /f
    reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaverIsSecure /d "1" /t REG_SZ /f
    del %0
    (Please notice, there are no typos in above batch sample. First string uses label ScreenSave, the second ScreenSaver.)

    Syntax of reg add command:

    reg add "Key Name" /v ValueName /d "Value" /t DataType /f

    Valid data types:
    - REG_SZ = String value
    - REG_MULTI_SZ = Multi-string value
    - REG_EXPAND_SZ = Expandable string value
    - REG_DWORD = DWORD 32 bit value
    - REG_QWORD = QWORD 64 bit value
    - REG_BINARY = Binary value

    The /f switch forces writing the new value without prompting the user.

    Last but not least, if you want this batch to be run only once when first initial user signs in to Windows, but not later when additional users sign in, save the batch in %programdata%\Microsoft\Windows\Start Menu\Programs\Startup instead of %appdata%.


    Try3 said:
    You can get the batch file to delete itself by putting a del command on the last line of the batch file.
    DEL alone is not enough. Name of current batch process is stored in variable %0, the last line of batch should therefore be del %0.

    Kari
    Last edited by Kari; 13 Aug 2017 at 09:26. Reason: Bad context changing typo
      My Computer


  4. Posts : 34
    Windows 10 Pro x64
    Thread Starter
       #4

    When I used the answer file that I had on my external storage device when i sysprepped, everything seemed to go fine when the computer shut down but when the computer restarted we had an issue where it was just stuck at the customizing your keyboards and default timezone screen and after you clicked on next, it just was stuck on "just a moment" for hours. Kari, your tutorials on sysprepped machines states (from my understanding) that in order to make an unattended answer file in windows SIM, you have to have the windows ISO image of the computer you're working on. However this is not the case as I do not have the exact image that is on these computers from Dell. I was just trying to use the image that was already on the machine to make my changes and then sysprep that machine to all the rest of the computers. Thanks
      My Computer


  5. Posts : 17,661
    Windows 10 Pro
       #5

    afdude08 said:
    Kari, your tutorials on sysprepped machines states (from my understanding) that in order to make an unattended answer file in windows SIM, you have to have the windows ISO image of the computer you're working on. However this is not the case as I do not have the exact image that is on these computers from Dell. I was just trying to use the image that was already on the machine to make my changes and then sysprep that machine to all the rest of the computers. Thanks
    No, you can of course use any install.wim file to create catalog file in Windows SIM, as long as it is for the same Windows version. If you are creating an answer file on your technician machine for 64 bit Windows 10 version 1703, you need either a catalog file for that or if you don't have one, a 64 bit install.wim file from W10 version 1703 install media, be it ISO or USB.
      My Computer


  6. Posts : 34
    Windows 10 Pro x64
    Thread Starter
       #6

    Ohhhhh!!! That might be the fix!! I was using a 1703 iso image when i made my answer file but the computers are 1607 xD im a dunce lol. Thanks Kari i will try that monday and ill check back in here :)
      My Computer


  7. Posts : 17,661
    Windows 10 Pro
       #7

    afdude08 said:
    Ohhhhh!!! That might be the fix!! I was using a 1703 iso image when i made my answer file but the computers are 1607 xD im a dunce lol. Thanks Kari i will try that monday and ill check back in here :)
    I don't believe that is your issue, 1607 is close enough. What I posted is "the rule", official recommendation, but I have for instance successfully used 1607 catalog files for 1703 and vice versa. It's just that a new version can bring in a new answer file component that the old version does not recognize, or an answer file made with older catalog file might included components deprecated in later versions.

    If you replace all sensitive information like product keys, user and organization names in answer file with bunch of X's and Y's and post it here, we could take a look to see if there's something obvious that is causing your issues.
      My Computer


  8. Posts : 34
    Windows 10 Pro x64
    Thread Starter
       #8

    But see that's the thing the only thing that I use in my answer file was copyprofile I didn't have any other things set in my answer file that was the only thing that I had set. But ill post it monday
      My Computer


  9. Posts : 34
    Windows 10 Pro x64
    Thread Starter
       #9

    And i wished answer files were backwards compatible but i understand if deprecated component being an issue here
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 02:27.
Find Us




Windows 10 Forums