Windows 10: Batch file that runs once for all new user accounts


  1. Posts : 6
    Windows 10 Pro x64
       1 Week Ago #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 ComputerSystem Spec


  2. Posts : 170
    Windows 10 Home x64 and Pro x86
       1 Week Ago #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 ComputerSystem Spec


  3. Posts : 12,136
    Windows 10 Pro
       1 Week Ago #3

    afdude08 said: View Post
    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: View Post
    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; 1 Week Ago at 09:26. Reason: Bad context changing typo
      My ComputerSystem Spec


  4. Posts : 6
    Windows 10 Pro x64
    Thread Starter
       1 Week Ago #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 ComputerSystem Spec


  5. Posts : 12,136
    Windows 10 Pro
       1 Week Ago #5

    afdude08 said: View Post
    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 ComputerSystem Spec


  6. Posts : 6
    Windows 10 Pro x64
    Thread Starter
       1 Week Ago #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 ComputerSystem Spec


  7. Posts : 12,136
    Windows 10 Pro
       1 Week Ago #7

    afdude08 said: View Post
    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 ComputerSystem Spec


  8. Posts : 6
    Windows 10 Pro x64
    Thread Starter
       1 Week Ago #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 ComputerSystem Spec


  9. Posts : 6
    Windows 10 Pro x64
    Thread Starter
       1 Week Ago #9

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


 

Related Threads
Need help with batch file in General Support
No serious Batch file or scripting experience, so bear with me. We use a site for our business that has to run on IE and has to have the cache cleared a certain way sometimes for it to function. We have to go IE options, uncheck delete history on...
Batch File Help in Software and Apps
I've never dabbled much in batch files, as I've usually been able to find pre-made ones to do what I wanted. We have an application that handles user data backups. It has three services, and at times, one or two of the three don't start...
Hi there forum, how do you change the Visual effects using a batch file or registry file. Thanks, Edward.
Hi I'm surprised that nobody else has this problem, but I've searched and can't find an answer...apologies if I've not looked hard enough but I decided to post a question because this is 'urgent' to me. I had 2 children's accounts in Win 8,...
Solved User accounts and Microsoft accounts in User Accounts and Family Safety
Our genealogy club has a room with a few PCs that members may use to access online databases the club pays for. With Windows 7, members use a flash drive for data transfer between their home PC and a club PC. If a member had a Microsoft account...
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 10:50.
Find Us