Im currently creating a uninstallation application which deletes the application folder. The problem is that i cant delete the uninstaller application which is in the same folder cause its running.
Is there a way to delete the application while running, so its just in the memory.
string Installation = UninstallRegister.Read("InstallationLocation");
if (Directory.Exists(StartMenu))
{
Directory.Delete(StartMenu, true);
}
Best regards
A simple idea would be to copy the uninstall application to %TEMP% and run from there. This would however leave a file in %TEMP% (which would probably not be noticed by anyone).
You can use command prompt Del command
nircmd has a command named cmdwait
you can set a wait time to delete your file then close the application and let it delete
You can use this command. It close your app and start cmd remove directory command arter deley=3000
This solution remove app and folder.
Process.Start("cmd.exe", "/C ping 1.1.1.1 -n 1 -w 3000 > Nul & RD /s /q " + Path.GetDirectoryName(Application.ExecutablePath));
Application.Exit();
Related
I have a web application created using .net core 2. In the application, I have a backup feature. When button is clicked, the application will call the bat file with parameters using ProcessStartInfo().
Everything is okay in the development week, I don't encounter any errors and my .bat file is doing everything it is told to do. But when I deployed the project into the production server, it seems almost all of the command inside the .bat file is not working at all.
I have two windows computers. I deployed the project in computer2 in IIS. Then I access the project in my computer1. I developed the project in computer1. Note that the application have web and api projects.
Here is the folder structure of computer2:
C:\Project\
|-- api\
|-- web\
|--script\Backup.bat
the WEB is calling the API, then API is calling the Backup.bat by:
ProcessStartInfo info = new ProcessStartInfo(#"C:\Project\script\Backup.bat", "param1"));
var process = Process.Start(info);
process.WaitForExit();
the following commands inside the Backup.bat is not working:
xcopy /S /I C:\data1 C:\backup\data1
SQLCMD -S .\SQLEXPRESS -U root -P root -Q "Backup Database myDatabase To Disk='C:\backup\myDatabase.bak'"
but other commands like MOVE, ECHO, MKDIR is working properly.
It only won't work, when called using the web app, but when called from command prompt it is working properly.
Also I made it work by adding START command before xcopy and SQLCMD, sample is: START XCOPY /S /I .... and START SQLCMD ....
but is it possible to make it work without start command? The start command opens new prompt and I don't want that.
My question is, how can I make my .bat file work in production server as it worked in my development's? Thanks!
My application call msiexec to run uninstall.
logger->LogDebug("Actions: MsiUninstallExec()!");
System::Diagnostics::Process ^p = gcnew System::Diagnostics::Process();
p->StartInfo->FileName = "msiexec";
p->StartInfo->Arguments = "/x " + AppSetting::ProductCode;
p->Start();
/// -->>> Uninstall
/// -->> Choose restart or not.
/// -->>> Application Exit
When uninstallation is done, users have to choose restart or not to complete this process.
But my customer request : "The progress bar of msiexec must move to the last (right end)."
How to edit it ? Do you have any idea for me?
Suggestion: You can try something like this (find product GUID):
msiexec.exe /X {PRODUCT-GUID} /QN REBOOT=ReallySuppress /L*V "C:\Temp\msilog.log"
Quick command line explanation:
/X {PRODUCT-GUID} = run uninstall sequence for specified product
/QN = run completely silently
/REBOOT=ReallySuppress = suppress reboot prompts
/L*V "C:\Temp\msilog.log" = verbose logging at specified path
Alternatives: There are many ways to invoke MSI uninstall: Uninstalling an MSI file from the command line without using msiexec. You can uninstall via: msiexec, ARP, WMI, PowerShell, deployment Systems such as SCCM, VBScript / COM Automation, DTF, or via hidden Windows cache folders, and a few other options.
msiexec.exe: There are two flavors of the msiexec.exe command line. An original one and a later one that added the "full word" switches such as /quiet and /noreboot and the likes. The original command line used /qn as the switch for silent mode. Here are links to both flavors: MSIEXEC what is the difference between qn and quiet.
Some Links:
Silent installation of a MSI package
How can I find the product GUID of an installed MSI setup?
How to report msi installation status on quiet install
msiexec /passive /x ProductCode
This should give you just the ProgressBar UI. You can also ask the user whether they want to skip restart or always force restart when the Uninstall completes. Then can add the /norestart or /forcerestart option appropriately.
I tried to establish a process through a click button where I can do following activities.
Objective
Download the latest code from SVN.
Build 2 set of Codes to create dlls and exe-
(a)Web application in Release mode
(b)Standalone application in debug mode
Then Replace some values of keys inside config files.
Then Place them to particular location.
Steps followed so far
Created demo.bat file which will build exe and dlls for Standalone as shown below
REM * ============================Starting Setup for Standalone======================================
SET Folder= C:\Automating\Application\Source\StandaloneApp\
cd %Folder%App1
msbuild /property:Configuration=Debug App1.csproj /t:clean /t:build
cd %Folder%App2
msbuild /property:Configuration=Debug App2.csproj /t:clean /t:build
del /F /S /Q /A %Folder%Setup\*.*
XCOPY %Folder%App1\bin\Debug\*.* %Folder%Setup\*.* /S /Y /F /Q
XCOPY %Folder%App2\bin\Debug\*.* %Folder%Setup\*.* /S /Y /F /Q
Created Another bat file demo1.bat to change command prompt to VS2010 cmd prompt
%comspec% /k ""c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86
%comspec% /k ""C:\Automating\BuildAuto\BuildAutomation\demo.bat""
Created one more cmd files to download from svn
TortoiseProc.exe /command:export /URL:[URL path] /Path:"C:/Automating/Demo"
Finally A web application where from user can click button to download as per svnExport.bat and build the downloaded code as per demo1.bat.
protected void Button2_Click(object sender, EventArgs e) {
ProcessStartInfo psi = new ProcessStartInfo(#"C:\AutomatingPOC\BuildAuto\BuildAutomation\demo1.bat");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = false;
psi.CreateNoWindow = false;
Process.Start(psi);
}
Downloading event is working correctly, but build is not working. I need help on how can I build the code
Why reinventing the wheel? Use available tools, such as TeamCity and msbuild (there are plenty other alternatives as well).
I found Eugene made a really nice introduction here.
People spent man-years developing and polishing build automation tools. If I were you, I would stop right there and had a look around.
if you set psi.UserShellExecute to false, then you will need to specify that the command to execute is actually "cmd.exe" and that the batch file is an argument. You'll also have to manages the delay between the time that the request is made and the time the build is actually completed.
automating a task like this can be done easily with Auto Hot Key. also to automatically download you can use the start command and the type of browser of your choice IE Firefox iexplore chrome ~ then you can automate the download. but do note that with some websites page number may change IE.This address has a specified page code:
Try to Automate the Build Process for C# Solution through user click
so instead of putting the regular address in the batch or what ever you chose to use you can put in
https://stackoverflow.com/questions/********
allowing it to find the information
or you can use a mouse/key-board recorder to automate the task.
I am trying to use iexpress to run my batch file which will execute the 2 exe & 1 msi files for me. when i try to do it manually, it works.
following is the code in my batch file.
Start /wait %CD%\1.exe /q
Start /wait %CD%\2.exe /q
msiexec.exe /i "%CD%\3.msi"
but this doesn't seem to be working when i create an exe file from iexpress.
Reference
Above mentioned article has some code(to copy files to temp folder) & but i am not able to understand the syntax.
MKDIR %Tmp%\<UNIQUE PRODUCT NAME>
XCOPY . %Tmp%\<UNIQUE PRODUCT NAME> /S /E /Y
%Tmp%\<UNIQUE PRODUCT NAME>\setup.exe
The problem is that, as you can see from your screenshot, the batch file is being executed by command.com, not cmd.exe. (If you don't specify an interpreter, IExpress uses command.com. Ouch.) So there are no variables like %cd% or %~dp0.
You likely don't need them anyhow. But you do need to execute your batch file explicitly in IExpress like:
cmd.exe /c file.bat
so that it uses a modern command interpreter.
The second bit of code in your question makes the files persistent (ie they won't be deleted after the IExpress archive terminates) by xcopying them to a different directory.
Here is what it means:
1) Creates a directory(MKDIR) with name of "UNIQUE PRODUCT NAME" in the path stored in %TMP% Environment Variable, which normally points to: C:\DOCUME~1\yourusername\LOCALS~1\Temp
MKDIR %Tmp%\<UNIQUE PRODUCT NAME>
2) Then copy recursively all installation files from current folder into the new folder created before.
XCOPY arguments:
/S Copies directories and subdirectories except empty ones.
/E Copies directories and subdirectories, including empty ones.
Same as /S /E. May be used to modify /T.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
XCOPY . %Tmp%\<UNIQUE PRODUCT NAME> /S /E /Y
3) Finally execute the application from the new location
%Tmp%\\setup.exe
Hope this helps
Try replacing %CD% with %~dp0
Assuming that 1.exe is in the same folder as your batch script.
Your %CD% is not working. Please be sure that CMD extensions are enabled (type CMD /x to enable and CMD /y to disable) then expand the %CD% with this code
SET CURDIR=%CD%
Start /wait "%CURDIR%\1.exe" /q
Start /wait "%CURDIR%\2.exe" /q
msiexec.exe /i "%CURDIR%\3.msi"
And I'm not sure that you can start an exe from that location (APPDATA) for security reasons.
Thanks a lot for this forum discussion.Finally i could able to compile all msi files and executables in an one .exe file.
Complete procedure as follows create a batch file
echo on
SET CURDIR=%CD%
msiexec.exe /i "%CURDIR%\1.msi"
"%CURDIR%\3.EXE"
"%CURDIR%\setup.exe"
echo off
You can arrange any number of exe files or msi files as you wish and save the batch file as yourfile.bat.
Now the tricky part is before you proceed to Iexpress, convert the batch file to exe with the software provided by http://www.f2ko.de/programs.php?pid=b2e
Now when you run the program keep the 'Invisible Application' checked to hide the command prompt.You can also encrypt your exe with the password.'Delete at Exit' is optional as the temporary folder will be automatically deleted when the execution of files completed.
Once you successfully compile the batch file,execute the .exe file created.
Bingo!! you'll not see the command prompt window and your applications start executing sequentially.
Begin your Iexpress tool and Add all your files present in the batch file(except batch file).On the ‘Install Program to Launch’ screen, leave the Post Install Command blank and find the following in the Install Program dropdown:'demo.exe'and proceed further to create your complete bunch of single package. Cheers!!
I am creating MSI installer via VS 2008. I try to delete the temp folder at the end of the installation. That temp folder is created by my installer to hold some batch files for database creation. It always show other process is access it and doesn't allow my code to delete it. I have called the Close() of that access process. I have put sleep before the code to delete it. Nothing helpful.
Do you have any idea how I can delete it at the end of the installation?
thanks,
Did you try Filemon to see who is accessing the temp folder when delete is called on the folder?
Its better you use the system temp folder path
System.Environment.GetEnvironmentVariable("TEMP")
you need not worry about cleaning it up.
I can think of creating a batch file in the temp folder to run which runs as the last step. You put a pause in it by using ping (http://www.robvanderwoude.com/wait.php) and then after a few seconds (that installer has exited) delete the folder by using parameter passed:
PING 1.1.1.1 -n 1 -w 60000 >NUL
rd "%1"
This is really a hack. It is better to root out what locks your folder.
I'll address the conceptual problems in your setup first:
First off, as "Vinay B R" said, be sure your "temp" folder is beneath the Windows %TEMP% folder. That way, you can leave the files there if you fail to delete them.
Why exactly do you want to delete the batch files when you're done? There is no expectation that you clean up after yourself inside of the %TEMP% folder.
If you want to ensure the user doesn't run them again, then you could name them with a different file extension (e.g. ".tmp" instead of .bat), execute them using this method described here, then leave them behind:
cmd < "%TEMP%foo.tmp"
If you are trying to delete files because you don't want the user to have access to them, then by deleting them you will only protect yourself against casual users.
If you still want to delete the files, then:
In all likelihood your own process is locking your folder. Using Process Explorer will likely point to msiexec.exe or cmd.exe. No doubt you are able to manually delete the folder once MSI and SQL have exited, right? If so, then your own process isn't terminating right away. Find out why. Is SQL taking longer than you think, perhaps?
As an alternative to Aliostad's method, here is the "other flavor" listed in this article. As he wrote, however, it would be best for you to determine why it's locked.
Process.Start("cmd.exe", "/C choice /C Y /N /D Y /T 3 & Del " +
Application.ExecutablePath);
Application.Exit();
Here is a working sample in C#. If your users will have .NET installed, then you can invoke this as a custom action using the WiX DTF (install WiX, then in Visual Studio select New Project -> Windows Installer XML -> C# Custom Action Project).:
// Note: This can also be used to delete this .exe (i.e.
// System.Windows.Forms.Application.ExecutablePath).
//
public static void AsynchDeleteFolder(string myTempFolderPath)
{
ProcessStartInfo info = new ProcessStartInfo();
// Don't create a visible DOS box.
info.WindowStyle = ProcessWindowStyle.Hidden;
info.CreateNoWindow = true;
// Wait 3 seconds ("/T 3").
info.Arguments = #"/C choice /C Y /N /D Y /T 3 & rmdir /S /Q """ +
myTempFolderPath + #"""";
info.FileName = "cmd.exe";
Process.Start(info);
}
If you would rather execute just the applicable portion as a batch file, then you can avoid the DOS window by following this method.:
' Filename: Run_a_batch_file_with_no_popup_dos_box.vbs
'
' Invoke like this from the command line:
' wscript.exe Run_a_batch_file_with_no_popup_dos_box.vbs "c:\path with spaces to my file name.bat"
'
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & WScript.Arguments.Item(0) & Chr(34), 0
Set WshShell = Nothing