I have a web application, that sometimes hangs. I want to investigate the reason, and I need to get a memory dump of the process, when it hangs.
So my idea is to monitor the website, when I am detecting the hang, I want to start a .bat script which captures the memory dump, then runs IISRESET in order to restart so that the site will start responding again.
My problem is, that adplus starts another process (cdb.exe) and returns immediately. I need to wait for cdb.exe to finish, before I can run IISRESET. Is there any way to do that in a batch script ? Or, can I specify on the adplus command line, that it should not return until the memory dump has been collected ?
Regarding the second part of your question, the answer is yes: you can both (1)specify the wait on the commmand line (as long as you can access to and modify it); and (2)wait for a process to finish in a batch file.
In their simplest form, do
(1) use START /WAIT cdb parms instead of just cdb parms
(2) try FOR /F "tokens=1,2" %a in ('TASKLIST ^| FIND /I "cdb.exe"') DO #ECHO %a %b and substitute ECHO for the command you want.
To create the memory dump of your web application, the Microsoft Debug Diagnostic Tools are your best option.
You can create an "IIS Hang" rule, monitoring a specific URL, and creating a memory dump whenever no response is received within a specified number of seconds.
The Debug Diagnostics Tools will not help you with regard to restarting IIS (or your app pool), but in general the built-in Application Pool restart options should be sufficient for that. If you make sure "Enable Pinging" is set for your AppPool (on its Health tab), and you also set the other Health/Recycling parameters appropriately, your app should continue responding no matter what happens.
If not, monitoring the output folder with crash dumps from your "IIS Hang" DebugDiag rule, and restarting IIS whenever new files appear should definitely do the trick...
Related
I need to ensure that a particular service is always running on the computer. To do this, I use a bat with the command
sc start "servicename"
However, if the service has been marked for deletion, I get the above error. So, what is the proper way to solve this situation via bat?
This means, you have done commandline deletion of the service, however the services.msc is not reloaded with active services.
Try running delete service again, atleast you can make sure its marked for deletion or requires again (SC DELETE shortservicename)
Kill any .exe process associated with the service
Adding this before SC command most probably, this will force stop any processes
taskkill /F /IM service_name.exe
If this issue still not fixed, just restart the PC and try again. I had the same problem, and got resolved after PC restart.
How do i do this?
i've tried all i can think of.
Browsing for my .exe file i want to run.
run a bat file
writing forcedos.exe in program textbox and path to my bat file in command line parameters textbox
Why cant it just work with an normal exe?
and i know it should run a program because it can restart the service correctly.
EDIT
Application: test.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Exception
This is my latest try to make it work.
the script has the code
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("iexplore")
Set objShell = Nothing
Now the script opens internet explorer if i run the cmd command
wscript.exe "C:\asfh.vbs"
The "run a program" recovery option for when a service crashes runs the specified executable in the same way as the service, i.e., it runs in session 0 (and so is affected by session 0 isolation, see also related questions) and it runs with the same security context as the service.
This means that it can't interact directly with the user (you can display a GUI, but nobody will see it) but it also restricts what the executable or script can do. For example, some shell API functions will not work properly unless the user account has been interactively logged in at some point. In the example script you posted, the script itself is probably running, but is unable to launch Internet Explorer because IE is only designed to run in an interactive session.
Provided you restrict yourself to basic functionality, it should all work as expected. (There is no master list that I know of describing what functionality is safe to use in a service context, but it is usually easy to guess. You can resort to trial and error if necessary!)
Also note that as far as I know forcedos.exe is no longer present in modern versions of Windows. If you want to run a batch file, you can specify cmd.exe as the application and /c myscript.bat as the command line parameters.
I have a batch file which uses gpresult /v and saves the output in a text file and copy that text file to a shared folder. This batch when i run on my local machine works perfectly fine but once i deploy it through SCCM it says can not open file with error code 4. I dont know what is wrong in the file.
the code is Like this:
#echo off
gpresult /v >%computername%.txt
xcopy %computername%.txt \some path
Error 4 is "The system cannot open the file.", as if the path is invalid or the open() fails for some other reason.
Do you know what directory the program is running in (CWD)?
That's where the results of gpresult are going (if the output redirection succeeds).
gpresult is not going to produce meaningful user-level data for the SYSTEM user.
Perhaps you should use gpresult /v scope computer.
Why are you using xcopy when you're only copying one file? xcopy really only has added value (over copy) if you are copying directories.
xcopy's behavior changes depending on how you specify the target. If the target ends with the directory separator (backslash), xcopy treats it like it's a directory. If it doesn't and the target doesn't exist, xcopy asks you what to do, which causes automated processes to pause indefinitely waiting for user input.
SCCM Programs Run as 'NT Authority\SYSTEM'
When SCCM (2007) runs a program, the program doesn't run as a regular user. It runs as the highest privilege user (sort of), SYSTEM.
This account is not a regular account, and many settings and environment variables that exist and are predictable for a regular user are different or do not exist for SYSTEM.
One particularly frustrating "feature" of the SYSTEM account's profile is that it is nestled away under %WINDIR%\System32, and so it is subject to filesystem redirection whenever you refer to anything relative to the profile.
Try this: use psexec -s (sysinternals) to get shell access as the SYSTEM account and run the command in that environment to see how it behaves. This is as close as we can get to an environment like the one SCCM programs run under.
When SCCM runs the command, the CWD will probably be somewhere under %WINDIR%\SysWOW64\CCM\ and may be invoked with the 32-bit version of CMD.EXE.
I have a question in regards to something similar to this. So I have an uninstall bat that runs. Due to the vendors uninstall it causes a force close of the windows explorer UI. So in haste to solve that issue I added a call to open explorer.exe. There is a problem with this as someone pointed out to me. Actually as soon as he said I knew exactly what he was saying and where he was going with his statement. Calling explorer.exe would be fine except that the bat is running under the system context not the user so when explorer is restarted it will start under the guise of the system desktop profile not the user's. I know there is way to still run under the guise of system but to restart explorer under the currently logged in user's profile.
Probably a really obvious question, I'm trying to run some sequential batch code to define my own eclipse external run configurations.
One of the calls in the .bat is to run a jetty server, and after this I want to launch a program. At the moment the execution of the .bat means that the call to run jetty hangs on that call, and the call to open the program is only executed once the jetty server has been killed.
Is there any way I can run the call to start jetty, and then immediately run another call to open any program that wont have to wait for the server to be killed.
You can use start to run a program in the background explicitly:
start "" "C:\Program Files\etc.\blah\x.exe"
Execution of the batch file immediately continues after that line. In case of jetty you're probably starting Java anyway. cmd doesn't wait for GUI processes so you can also use
javaw -jar ...\jetty.jar
instead of calling java.
Since the question has changed a bit after the comment:
If there is a reliable way of knowing when jetty has started, e.g. a file that will exist somewhere
:l
timeout /t 1 >nul
if not exists %temp%\somefile goto l
you could use that. Otherwise you can just wait for a while
rem wait two minutes
timeout /t 120 > nul
and hope that everything has started by then.
I'm making a Cloud Drive program for my university (like dropbox for example, but much simpler), which let users automatically upload files on a server and share them with other users
I wanted to make an option, so that if someone boots the machine, the process will start automatically
What I think I have to do is to add an entry in the register at the key: HKEY_LOCAL_MACHINE/sofware/Windows/CurrentVersion/Run and I wrote these lines of code:
system("REG ADD HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /v uCloud.exe /t REG_SZ /d \"C:\\Desktop\\uCloud\\uCloud.exe\" /f");
I also tried with the functions: RegOpenKeyEx and RegSetValueEx
the problem is that in both the cases I need administrator rights
If I edit the HKEY_CURRENT_USER the program automatically starts on boot, but it doesn't work at all (I mean I see the process, but it does nothing. I have to close the process and open it again manually and then it starts to download and update the stuffs)
Thanks a lot
When you use the task scheduler, you can use admin rights; see here: http://www.techrepublic.com/blog/window-on-windows/make-vista-launch-uac-restricted-programs-at-startup-with-task-scheduler/616