Scripting Sysprep - scripting

I'm trying to create a script that will automate the sysprep process but I'm running into issues with the reg add command. I keep getting Invalid Syntax even though everything looks correct according to the reg add /? command.
Here's the script:
reg add HKLM\SYSTEM\Setup\Status\Sysprepstatus /v CleanupState /t REG_DWORD /d 00000002
reg add HKLM\SYSTEM\Setup\Status\Sysprepstatus /v GeneralizationState /t REG_DWORD /d 00000007
reg add HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform /v SkipRearm /t REG_DWORD /d 00000001
msdtc -uninstall
timeout 120
msdtc -install
timeout 120
"C:\Windows\System32\Sysprep.exe" /oobe /generalize /shutdown
Any help would be appreciated. Thanks in advance!

The reg add command works for me, however cmd is running as an Administrator. That might be what's causing you problems.

Related

Adding Registry Keys on Remote Windows Server Machine not working

I have two domain joined machines (ServerA & ServerB) running Windows Server 2012 R2.
I want to add new registry key in ServerB from ServerA.
I am running below command in ServerA:
reg add \\ServerB\HKLM\SOFTWARE\MyCompany\MyApp /v Username /t REG_SZ /d ABC123 /f
Output from above command: The operation completed successfully.
But when I checked registry in ServerB, I didn't find the newly added key.
I am using MSBuild to run this command inside a script in ServerA.
Deploy.proj
<Target Name="Deploy_Registry">
<!--Make sure the Remote Registry service is started-->
<ServiceController MachineName="ServerB" ServiceName="Remote Registry" Action="Start" ContinueOnError="true"/>
<Exec Command='reg add \\ServerB\HKLM\SOFTWARE\MyCompany\MyApp /v Username /t REG_SZ /d ABC123 /f' ContinueOnError='false' /></Target>

UiPath: error in iTextSharp at my custom activity [duplicate]

I have used itextsharp library to generate pdf in my asp.net web application. It was working fine untill today when suddenly my laptop on which the application was running in the debug mode went off. When I switched on my laptop again and tried to run the application I satrted getting this error:
"Could not load file or assembly 'itextsharp, Version=5.5.0.0,
Culture=neutral, PublicKeyToken=8354ae6d2174ddca' or one of its
dependencies. The parameter is incorrect. (Exception from HRESULT:
0x80070057 (E_INVALIDARG))"
What could be the reason and how can I solve this? Please help.
Try removing the reference and add again...!!! Seems like the reference got removed due to improper shutdown.
Try to clean Temporary Files of Asp.Net, sometime I've experimented strage cases of files corruption(I know this should be a comment but It's verbose):
1 - Open notepad and paste the following.
#ECHO OFF
ECHO Per­form­ing IIS Reset
IISRESET
ECHO Delet­ing Cache
Del /F /Q /S %LOCALAPPDATA%\Microsoft\WebsiteCache\*.*
Del /F /Q /S %LOCALAPPDATA%\Temp\VWDWebCache\*.*
Del /F /Q /S “%LOCALAPPDATA%\Microsoft\Team Foundation\3.0\Cache\*.*“
Del /F /Q /S “C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\*.*“
Del /F /Q /S “C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\*.*“
Del /F /Q /S “C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\*.*“
Del /F /Q /S “C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\*.*“
ECHO Complete
2 - Save the file as a .bat file.
3 - run it from the com­mand prompt.
I had a backup of my project. Restored the backup and it worked. Thanks for all the suggestions.

How can I pass a powershell variable into a CMD command?

I am trying to run the following command through powershell:
schtasks /query /s $compname /v /fo csv | ConvertFrom-Csv
$compname is set in the first part of the powershell script, but cannot be passed into the command like this. For example, when I try passing in $localhost, I get the following error:
ERROR: Invalid syntax. Value expected for '/s'.
Type "SCHTASKS /QUERY /?" for usage.
Is there a way to pass the variable into this command? I don't plan to change to powershell's native way to access scheduled tasks (through a COM object).
Working for me, tested in v2. Does it help if you enclose the variable in double quotes (e.g "$compname") ?
$compname = 'localhost'
schtasks /query /s $compname /v /fo csv | ConvertFrom-Csv
Try this:
Invoke-Expression -Command "schtasks /query /s $compname /v /fo csv" | ConvertFrom-Csv

Passing CMD Results to Variable in a Batch File

I am trying to install an application and a group of services using PSTools, but I want to take into account that the computer I am trying to connect to may be turned off or on a different network, which is not reachable from the internal network.
Basically if the machine is not able to be accessed through the admin share, this is the message that I am getting:
Couldn't access MachineName:
The network path was not found.
Make sure that the default admin$ share is enabled on MachineName.
This is the syntax I am using to try to capture the "Error Message" and then report back that if installation was successful or not (depending on if it can contact the machine)
#echo off
set /p name=What is the machine name?:
psexec.exe \\%name% -u *useraccount* -p *password* \\ServerName\installation.bat
FOR /F "tokens=*" %%A IN ('COMMAND ^| FIND "Couldn't access"') DO SET Error=%%A
If "%Error%"=="Couldn't access"
ECHO Installation Failed.
Else
ECHO Installtion complete.
Pause
exit
Currently it hangs right at the point it's defining the Error Variable. Can't quite figure out what I am going wrong here.
'COMMAND ^| FIND "Couldn't access"' opens a command shell, which is why it hangs. It will not proceed until that shell is exited.
You will need to look at redirecting the error messages to another file. 2>Errors.txt on the psexec line will give you a file to search in the next line.
this will make the batch file look something like this:
#echo off
set /p name=What is the machine name?:
psexec.exe \\\%name% ... \\\ServerName\installation.bat 1>Error.txt 2>&1
for /f "tokens=*" %%A in ('FIND /i error.txt "Couldn't Access"') do SET Error=%%A
If not x%ERROR:Couldn=%==x%ERROR% (
ECHO Installation Failed.
) Else (
ECHO Installtion complete.
)
Pause
exit
(Also, notice the use of brackets to make a multi line IF)
the check for if will see if Couldn is part of the string, as a direct comparison will not work, as you would have to check against the whole string including the machine name

How to check if a particular command line is running in cmd propmt

I desperately need help to create a vb / dos code which will do the following:
Check if a command prompt window is running with the following command: mgms A1 (mgms is a custom command)
If it is running, exit.
If it is not running, start cmd prompt and run the command , exit
Thanks a lot for your help!
The Windows cmd.exe batch language is horrible, but you should be able to put this in a batch file and get it working:
tasklist /FI "IMAGENAME eq mgms.exe" 2>&1 | findstr /B "INFO: No tasks running" > tmp
for /F "delims=" %x in (tmp) do mgms A1
You may need to further check that the command-line arguments to mgms.exe match what you expect -- have a look at the help for tasklist.exe and findstr.exe. Both programs are both standard in WinXP Pro and up, I believe. If you don't have them, I'm sure you can find them or (near) equivalents on the web.