I would like to write a script and run it from my local PC to stop and start an application pool and site that exists on a server.
Value of App Pool and Site - Test
Value of server - SERVER1
Any guidance would be much appreciated.
Run Command Prompt with Administrative rights, and type the following:
C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:"MYAPPPOOLNAME"
or use the stop command. You could save this in a batch file, but it must be executed with higher privileges.
For the application pool on a remote server, you could use PsExec:
Psexec \\{Computer Name of ISS7 Server} C:\Windows\System32\inetsrv\appcmd recycle apppool my-app-pool
Related
We are trying to integrate MicroFocus UFT testing into an Azure DevOps CI\CD pipeline using a self-hosted EC2 build agent (let's call the build agent UftServer). UftServer has MicroFocus UFT One installed and the pipeline uses the MicroFocus Azure DevOps extension see here to start the test.
Everything works as expected when a full screen RDP session is open to UftServer. When the pipeline runs, we can watch UFT One open our application and run the specified test. Results post back to Azure DevOps with pass\fail and life is good.
However, when the RDP session is closed, the UFT pipeline step fails to execute the test. It mentions a credentials error, but the problem clearly seems to be the closed RDP session.
From the test results we assume that a full screen RDP session needs to be active for UFT One to execute the tests properly (it detects the screen resolution so that it knows where certain menus are in our application).
So, rather than open the RDP session to UftServer from my local system (which won't necessarily be open when the pipeline runs), we created a second build agent RDPLauncher in the pipeline (also self hosted EC2), and execute the following script on it before launching the UFT test on UftServer:
$RemoteUftServer = "UftServerIp"
$RemoteUftUser = "Administrator"
$RemotePwSecretId = "uft"
$RemoteUftPw = ((Get-SECSecretValue -SecretId $RemotePwSecretId).SecretString | ConvertFrom-Json).password
reg add "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client" /v "AuthenticationLevelOverride" /t "REG_DWORD" /d 0 /f #to disable cert check
cmdkey /generic:"$RemoteUftServer" /user:"$RemoteUftUser" /pass:"$RemoteUftPw" #to set RDP creds
mstsc /v:"UftServerIp" /admin /f
Write-Host "mstsc command ran successfully, qwinsta results:"
qwinsta
When we run this script manually RDPed into RDPLauncher, the full screen RDP session to the UftServer opens as expected and runs the test.
Further, we can disconnect from RDPLauncher and the RDP session from RDPLauncher to UftServer remains open and the pipeline still runs successfully.
It is great to not have the RDP session open from my local system, but the pipeline still lacks a critical automation piece.
When the pipeline runs the above script on RDPLauncher (rather than me running it manually RDPed into RDPLauncher), it succeeds, but then the UFT test fails as if the session isn't open.
So, from the pipeline, how do we remotely open the full screen RDP session from RDPLauncher to UftServer?
The script above works when I run it from RDPLauncher, but doesn't seem to have the same effect when the Azure DevOps Agent service runs it from the pipeline.
Both build agents are running Windows 10.
Any help is appreciated :)
I suggest you to first configure everything before the pipeline run.
1, Remember the credential.
2, After the above steps, click remember your password after you input the password.
And then, in your pipeline, only need a pipeline definition like the below will be able to connected to the remote server with rdp file(no need other interactive steps.):
trigger:
- none
pool: VMAS #This is a self hosted agent pool, the pipeline is runnning based on a server in this agent pool, and the rdp file is also in this server.
steps:
- script: |
# echo %username%
# mkdir "C:/xxxyyyzzz"
C:\Users\Administrator\Desktop\VM.rdp # Here is the path of the rdp file on my side.
displayName: 'Run a one-line script'
I need to stop and start IIS server for TFS build. When do this using .bat file iisreset /stop, similarly for start.
When I do this I get
Access denied, you must be an administrator of the remote computer to use this command. Either have your account added to the administrator local group of the remote computer or to the domain administrator global group.
Please note: This is Windows server 2019
I am already admin of this machine.
I have given read/write access to everyone in this folder.
I have unset EnableLUA to '0' in the registry as told in link for site
Above all these, I restarted machine.
I still get error in TFS build.
When you start a build in TFS the execution of that build is effectively done by a build agent. A build agent is just a service running on any particular machine. So, your batch file that shall start/stop the IIS service will be executed by whatever build agent is running your particular build.
This in terms means that your batch file is executed by the user that is used to run the build service. If that user does not have the necessary admin rights you face this particular error message.
What you need to do is make sure that all accounts that you use to run your build agents have administrative permissions on whatever machine you want to start/stop IIS.
You are trying to do IISRESET in your batch script. You need to be an Administrator as basic right to execute IISRESET command. So the account which the build is running needs to be part of the Admin group on the box.
Other approach is to stop and start w3svc using sc config commands or NET STOP WAS /Y and NET START W3SVC
Both of your answers are correct, I added the 'Network Service' of TFS to admin group of machine. Then build was success. Administrative tools>Computer Management> Local Users and Groups>Groups>
Inside Administrators and Users add 'Network Services'. If you don't find 'Network Service' then change location to your computer node and add them.
Is it possible to run JMeter server as a service in windows?
Currently I'm just logging in and running it manually, but from time to time I have to restart this machine and I would like to make JMeter server run automatically after each restart (even no user logs in after restart).
To create windows service sc create serviceName binpath= "path\to\exe"
You can also create a shortcut/bat file in the windows startup folder to start the JMeter. C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
You can also have a look at this - to start a program using windows task scheduler w/o user log in.
We have a server that is on the same LAN as my work computer. I know you can use "net stop" and "net start" in a batch file to restart a service on the local machine, but is it possible to do that for a remote machine?
I know you can use \computer to browse a networked machine, for example, so is there some syntax that would be something like \computer net stop service or so on?
Right now I have to Remote Desktop into the machine, restart the service, then log off, which is a hassle.
Create a Desktop shortcut
in the cmd to run enter :
sc \\server stop service
sc is the service management tool
server is your remote server name or IP
and finally service is the name of the service you target
I figured it out - for anyone else wondering: you can use this command:
C:\Windows\System32\runas.exe /savecred /user:[domain\user] "C:\windows\system32\cmd.exe /c C:\Test.bat" Where your batch file with the sc \server stop service is in C:\Test.bat. (You can move that around obviously)
I am looking to create new virtual directories on a remote server and set the app pool to a configuration other than the default. I am using NAnt but open to any other commands that can accompolish this.
Here is what I have tried:
<mkiisdir iisserver="${remote.server}" dirpath="${install.path}" vdirname="${vir.dir.name}" />
The above works fine in creating the VD to a remote server but the nant task does not have a parameter for specificing the application pool. Strange as to why not !!
I looked into using powershell to update the application pool since I already have the Virtual Directory created but due to my Windows OS restrictions I am unable to install the WebAdministration module which is required to update the IIS app pool.
Is there any existing method to accompolish this that I have not considered?
Thanks.
You can use AppCmd.exe which is located in the System32 folder.
appcmd set app /app.name:"Default Web Site/MyVirtualDirectoryName" /applicationPool:"MyAppPool"
If you need to Update the web applications directories on other servers remotely, then you can use PSExec \\RemoteServerHostname appcmd set app /app.name:"Default Web Site/MyVirtualDirectoryName" /applicationPool:"MyAppPool"