Silent Dropbox removal - windows

I use the following script in Npackd to uninstall Dropbox. It works on XP and Vista, but fails on Windows 7/64. Instead of showing the taskbar (the one that is normally at the bottom of the screen) it shows a Windows Explorer window with the content of C:/. This is not Dropbox related as removing other packages with DLL based shell extensions also shows the same effect.
Uninstall.exe /S _?=%CD%
taskkill /f /fi "IMAGENAME eq explorer.exe"
del DropboxExt.13.dll
del DropboxExt64.13.dll
rem start explorer from the root directory so it does not lock this one
start "" /D\ explorer.exe
What is wrong with the script? How can it be modified to work correctly on Windows 7 too?
Thanks
EDIT: I am really tired of this problem. The following batch file works either started as a normal user or "As Administrator":
taskkill /f /fi "IMAGENAME eq explorer.exe"
ping -n 5 127.0.0.1
pushd \
rem runas /trustlevel:0x20000
start "" /D\ explorer.exe
popd
Here is the code that starts the .bat from my program (path="Uninstall.bat", only 2 new environment variables are defined):
QDir d = this->getDirectory();
QProcess p(0);
p.setProcessChannelMode(QProcess::MergedChannels);
QStringList params;
p.setWorkingDirectory(d.absolutePath());
QString exe = d.absolutePath() + "\\" + path;
for (int i = 0; i < env.count(); i += 2) {
p.processEnvironment().insert(env.at(i), env.at(i + 1));
}
p.start(exe, params);
The corresponding code in Qt/qprocess_win.cpp:
DWORD dwCreationFlags = CREATE_NO_WINDOW;
dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
STARTUPINFOW startupInfo = { sizeof( STARTUPINFO ), 0, 0, 0,
(ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
(ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
0, 0, 0,
STARTF_USESTDHANDLES,
0, 0, 0,
stdinChannel.pipe[0], stdoutChannel.pipe[1], stderrChannel.pipe[1]
};
success = CreateProcess(0, (wchar_t*)args.utf16(),
0, 0, TRUE, dwCreationFlags,
environment.isEmpty() ? 0 : envlist.data(),
workingDirectory.isEmpty() ? 0 : (wchar_t*)QDir::toNativeSeparators(workingDirectory).utf16(),
&startupInfo, pid);
Why does the Explorer think there is already a taskbar?
EDIT2: I know what is wrong now. After the Explorer is killed a new is automatically started by an svchost.exe process with the following parameters: /factory,{682159d9-c321-47ca-b3f1-30e36b2ec8b9}. The GUID is for DesktopExplorerFactory. This is probably a crash-protection for a COM service. My calls to explorer.exe do not start a new Explorer as there is already one. After a minute or two this process will be automatically closed if no windows are opened. So I think Ben Voigt is right and "There's really no good way to unload the shell completely without logging off all users."

What is wrong with the script is quite simple: The shell is loaded into many many applications besides just Windows Explorer. Every application that uses the common open/save file dialogs hosts the shell.
To address your immediate question of how to control the working directory of Windows Explorer without passing arguments that open a window, just set the working directory:
pushd C:\
start explorer.exe
popd
But this still will not let you reliably delete the extension. There's really no good way to unload the shell completely without logging off all users.
EDIT: Is your script running at the same integrity level as the original explorer.exe you killed? Same elevation level? The shell runs with medium (normal) integrity level and unelevated token, you need to match this.

For what it's worth, your command "start "" /d\ explorer.exe" seems to work fine for me even on win7, it restarts the taskbar & desktop if it's been killed.
However, you don't really need "start". You can just call "explorer.exe" from a batch file, it won't block. Not sure if this makes a difference but it's worth a try.
By the way, if it doesn't work... what happens on the affected computer if you bring up the task manager with ctrl+shift+esc and do a File->Run "explorer"? Does that start the taskbar or will it, again, produce an explorer window? If this produces the expected results there may be something wrong with the batch file or its environment. Such as not being run as the currently logged on user, etc.
Explorer should start the taskbar if there are no other instances of its own process around. The fact that the shell itself may be loaded into other processes does not matter... you can kill all instances of explorer, have a "file open" dialog up in Excel, and still restart the taskbar by running explorer.exe from the task manager.

Try to replace the following line
start "" /D\ explorer.exe
with this one
start "" /D\ %SystemRoot%\explorer.exe
This should run explorer without parameters.
The thing is that running explorer without full path runs it with parameters you specified:
/factory,{682159d9-c321-47ca-b3f1-30e36b2ec8b9}
but I have no clue why this happens.

Related

Close opened cmd window from .bat file open application and execute file

I have a .bat file which opens an application and then executes a file that runs a job within the application. I cannot close the cmd window which opens when the task runs in windows task scheduler.
"C:\Proram Files (x86)\ \ \ Robot.exe" execute =f "S:\dept\ Team\ \ YearEndAudit\Main.xaml"
Any assistance would be much appreciated.
Regards,
Jeff
I may have misunderstood you, but what I understood was:
You are opening an executable with your CMD but are unable to close
the CMD after that.
I'm pretty sure that this amount of information is more than enough to solve your case, but we have very little data anyway, and the data is confusing. Please try to improve on your next post.
What is happening is that you are probably just putting the name of the program / script in your CMD, like:
program.exe
This causes the program to depend on the CMD to run, and also prevents the window from being closed. You can solve this problem using "start" at the beginning of everything, such as:
start "" "X:\Path\program.exe" execute -f "everythingyouwants"
You may need to be in the program folder, since some programs done lazily may consider your current location as the default location and may not find the dependencies they need.
If you care to stay in the folder you are currently in, you can use:
pushd "thepath\ofthe\program"
start program.exe
popd
Another way is to hide the window creating a script in VBS, such as:
Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c X:\YOURSCRIPTPATH\YOURSCRIPTNAME.bat/cmd"
oShell.Run strArgs, 0, false
However, if the path also needs quotes, we can have conflicts. The above is not ideal but may help sometime.
If none of this works for you, let us know.
Hope this helps,
K.

Execute a URL from a command line without opening a browser in windows

So I'm putting together a batch file to run at startup that executes a small number of processes, one of them is to execute a reboot of a certain program at the end of the set of processes. I've been searching ways how to do this in the command line in windows but I need to be able to do this without opening a browser. What I need is to execute the reboot in the following url without opening a browser at all.
http://192.168.1.100/cgi-bin/reboot
Everything that I've tried has opened a new browser window. I don't want to have to download anything to get this going in windows if that's possible. Thanks for any suggestions.
You know how sometimes the answer to the question you ask is not necessarily the answer you need? I have a vague suspicion this might be one of those times.
If this is a Windows machine you're trying to reboot, you can reboot it remotely without needing to use a CGI script served by the remote host. If the account you're logged in with on the triggering PC also has privileges on the remote PC, you can trigger the reboot with the shutdown command.
shutdown /m \\remotePC /r /t 0
Do shutdown /? in a cmd console for more info. Or if you must authenticate, you can use wmic instead.
wmic /node:remotePC /user:remotePCadmin /password:remotePCpass process call create "shutdown -r -t 0"
In case I was mistaken, here's the answer to the question you asked. The fastest way to execute a remote CGI script would be to use an XMLHTTPRequest with Windows Script Host (VBScript or JScript). Here's an example.
#if (#CodeSection == #Batch) #then
#echo off & setlocal
set "URL=http://192.168.1.100/cgi-bin/reboot"
cscript /nologo /e:jscript "%~f0" "%URL%"
goto :EOF
#end // end batch / begin JScript chimera
var x = WSH.CreateObject("Microsoft.XMLHTTP");
x.open("GET",WSH.Arguments(0),true);
x.setRequestHeader('User-Agent','XMLHTTP/1.0');
x.send('');
while (x.readyState != 4) WSH.Sleep(50);
For what it's worth, you can also parse x.responseText as needed. You can scrape it as flat text, or even evaluate it as a hierarchical DOM object. This answer demonstrates such parsing. And if you just can't get enough, here are more examples.
If you'd rather have something simpler at the expense of efficiency, you can invoke a PowerShell command.
#echo off & setlocal
set "URL=http://192.168.1.100/cgi-bin/reboot"
powershell "ipmo BitsTransfer; Start-BitsTransfer \"%URL%\" \"%temp%\a\""
del /q "%temp%\a"
goto :EOF
You could probably alternatively use Invoke-WebRequest to avoid the temporary file, but Invoke-WebRequest requires PowerShell version 3 or newer. Start-BitsTransfer works with PowerShell version 2, so it should work on more computers. One might also use the [System.Net]::WebRequest .NET class, but it gets a little complicated constructing all the objects needed to proceed beyond fetching the HTTP headers to having the web server serve the web page. If you're curious, it looks something like this:
powershell "[void](new-object IO.StreamReader([Net.WebRequest]::Create(\"%URL%\").GetResponse().GetResponseStream())).ReadToEnd()"
Not exactly what I'd call simple. In hybrid format for easier readability:
<# : batch portion
#echo off & setlocal
set "URL=http://192.168.1.100/cgi-bin/reboot"
powershell -noprofile "iex (${%~f0} | out-string)"
goto :EOF
: end batch / begin PowerShell hybrid chimera #>
$request = [Net.WebRequest]::Create($env:URL)
$response = $request.GetResponse()
$stream = $response.GetResponseStream()
$reader = new-object IO.StreamReader($stream)
[void]$reader.ReadToEnd()
In any case, any PowerShell solution will be a second or two slower than the JScript solution near the top of this answer. powershell.exe takes a second or two to load (indeed, several seconds if it's not been loaded since Windows was last rebooted); whereas cscript.exe fires nearly instantly.
If you cannot download anything, then Windows PowerShell is the best option. You can call it from a PS script file, or directly from the command line in a batch file:
powershell.exe -noprofile -command "Invoke-WebRequest -Uri http://192.168.1.100/cgi-bin/reboot"
You can also consider Curl for that type of process. There is no equivalent in Windows, so it will require a download.
curl http://192.168.1.100/cgi-bin/reboot
Curl will not open a browser window, and has great command line options (See curl -help), and will return error codes for batch file error handling.
I don't think Windows comes with that feature.
Try making a VBscript that will open the browser Windows but will not display anything maybe.
To process URL response direct, from Win CMD:
powershell "Invoke-WebRequest -Uri <url>"
To save server response to file:
powershell "Invoke-WebRequest -Uri <url> -outfile <file.ext>"
.NET solution; from Win CMD:
powershell "[System.Net.Webclient]::new().DownloadString(\"<URL>\")"

open program minimized via command prompt

I have a windows 8.1 machine and I want to open a program with minimized window.
For a program like notepad, I just use the following command:
start /min "" "C:\Windows\notepad.exe"
and then a new notepad window starts in minimized mode.
The problem is that not all programs do this. When I want to start for instance MS Word in minimized mode I use:
start /min "" "C:\Program Files (x86)\Microsoft Office\Office12\WINWORD.EXE"
but then a new Word windows starts up in MAXIMIZED mode.
Is there a way to start it minimized?
I tried this commands in my PC.It is working fine....
To open notepad in minimized mode:
start /min "" "C:\Windows\notepad.exe"
To open MS word in minimized mode:
start /min "" "C:\Program Files\Microsoft Office\Office14\WINWORD.EXE"
Try this
Go to the properties of the shortcut that points to the program (ALT ENTER or right click->properties); if there is no shortcut to it, you can make it by dragging and dropping the program while holding CTRL SHIFT;
Click in the Normal window dropdown, and choose minimized;
Save and run the shortcut.
You could try using the third-party tool called NirCmd. It is a genuine, free command line utility. If or when you have it, use this code in a batch file:
title Open Word
nircmd win hide title "Open Word"
start "C:\Program" "Files" "(x86)\Microsoft" "Office\Office12\WINWORD.exe
nircmd wait 20
nircmd win min foreground
exit
This program, in order, changes its title, hides itself according to its title, starts Word, waits 20 milliseconds as a buffer for Word to settle, minimizes Word by assuming it is now the top window, and then exits itself. This program should work as intended as long as their are no key presses or clicks in that ~50 millisecond time window, which shouldn't be hard.
As for installing nircmd on your computer, use this link, and click "Download NirCmd" at the bottom of the page. Save the .zip folder to a normal directory (like "My Documents"), extract it, and copy "nircmd.exe" to %systemroot%\system32, and there you go. Now you have nircmd included with your command line utilities.
Try:
start "" "C:\Program Files (x86)\Microsoft Office\Office12\WINWORD.EXE" --new-window/min
I had the same problem, but I was trying to open chrome.exe maximized. If I put the /min anywhere else in the command line, like before or after the empty title, it was ignored.
Local Windows 10 ActiveMQ server :
#echo off
start /min "" "C:\Install\apache-activemq\5.15.10\bin\win64\activemq.bat" start
Its actually not so simple.
It depends what you're trying to do and how the program behaves/interacts with Windows and UAC.
Certain programs will not start from a shortcut (for whatever reason that Windows determines). I have such a case with ViceVersa. I wanted to run the scheduler (VVScheduler) and no way could I get it to run via a shortcut in the user startup folder"s". Even with UAC disabled. Just would not start. Even tried adding it direct to the registry, no luck. So I was confined to using a batch file to run it at startup.
In my case I was unable to get it to open minimized, I tired the various syntax options offered in this post, none worked for me. I've resorted to just clicking the "-" on the VVScheduler window after startup.
For the people which are looking for the opposite (aka fullscreen), it's very simple. Because you just have to replace the settings /min by /max.
Now the program will be open at the "maximized" size !
In the case, perhaps you will need an example : start /max explorer.exe.
The answer is simple. Just look at the image.

Launch a program asynchronously at startup on Windows 7, just once, using only the registry

The program I am launching is the windows notepad (for a readme file after a program installation requiring a reboot). I am working in Windows 7 Professional, with administrator rights.
I would like to get the following solution working:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce
Name: myregentry
Type: REG_SZ
Data: notepad.exe C:\test2.txt
However, RunOnce is synchronous (http://msdn.microsoft.com/en-us/library/aa376977%28v=vs.85%29.aspx). This results in the notepad launching on top of a completely black screen (screenshot # tinypic), with no possibility to do anything but read the text. Startup waits, and resumes only after the notepad window is closed. This is not acceptable for my use (ti would confuse users).
I could get the following solution to work:
1) Create a registry entry:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce
Name: myregentry
Type: REG_SZ
Data: C:\launchreadme.bat
2) Create a self-deleting batch file at C:\launchreadme.bat:
#ECHO OFF
start notepad.exe C:\test2.txt
REM **** Delete this script ****
DEL "%~f0"
This does what I want. However I'd like to know:
Is there is a cleaner way to do this, without generating this batch file first, so: only using the registry?
This could be useful to others, as the web is full of example of "how to launch the notepad once from the registry", yet none of them (that I could find) mention this issue.
Additional information:
I could not get "start" to work in the registry entry (start notepad.exe C:\test1.txt does nothing on startup).
RunServicesOnce (instead of RunOnce), which used to launch programs once, asynchronously, apparently doesn't exist anymore in Windows 7.
Run (instead of RunOnce) is also asynchronous and works well. But obviously I don't want to launch this readme file after every reboot.
You can use the batch file approach without needing a batch file:
cmd /c "start notepad"

Restarting explorer.exe only opens an explorer window

The Problem
In one part of a batch file (kind of, see Extra Information) I need to restart
Explorer, so I use the, tried-and-tested method of
taskkill /f /im explorer.exe >nul
explorer.exe
Then this happens
explorer.exe is successfully terminated
explorer.exe is started (see Image 2), but only an
Explorer window opens, which I am left with indefinitely (see Image 1)
I can then only properly restart Explorer by starting a new task from Task
Manager, as, I'm assuming, Win + R is part of Explorer.
Extra Information
Now, I say "kind of" as I'm running the batch file from a self-executing SFX
archive, created with WinRAR. So, when executed, the contents of the archive are
extracted to %temp% and a user-defined file (usually a boot-strapper and, in
this case, my batch file) is run upon successful extraction.
So far, I've deduced
explorer.exe definitely is being fully killed.
The batch file definitely is called and executed correctly, as it runs and
everything else in the script works as designed, except for the line that
starts explorer.exe
The command to restart Explorer isn't "badly timed", or anything, as I've
tried delaying it.
The batch file works perfectly when manually extracted from the archive, so
it's not a problem with the compression or extraction processes.
Even with commands like start explorer.exe | cmd.exe Explorer doesn't
restart properly, so it's definitely not a problem with the .bat file.
I can confirm that it works on Windows XP and Windows 7 x86 but not Windows 7
x64 (which is my system).
Status
At the moment, I'm suspicious of WinRAR, as I've proved that the code itself
works. So, I'm creating the self-executing SFX with different versions of
WinRAR. So far, I've tried versions:
4.11 x86
4.11 x64
4.20b3 x86
4.20b3 x64
and had the same results every time.
I submitted a bug report to dev#rarlab.com yesterday and got a reply from
Eugene Roshal himself this morning
Hello,
SFX module uses ShellExecuteEx to start a setup application.
Normally it works well. I do not know why Explorer decides to switch
to windowed mode.
Now I built a small standalone program
#include <windows.h>
void main()
{
SHELLEXECUTEINFO si;
memset(&si,0,sizeof(si));
si.cbSize=sizeof(si);
si.lpFile="test.bat";
si.nShow=SW_SHOWNORMAL;
ShellExecuteEx(&si);
}
which runs test.bat with contents as in your sample. This program
shows exactly the same behavior as WinRAR SFX, so Explorer is started
in window.
and a second email this morning
Sorry, no advice now. I replaced ShellExecuteEx with CreateProcess
#include <windows.h>
void main()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si,0,sizeof(si));
si.cb=sizeof(si);
CreateProcess(NULL,"test.bat",NULL,NULL,TRUE,0,NULL,NULL,&si,&pi);
}
but result is the same. I tried to use other SW_ flags like
SW_SHOWDEFAULT or SW_RESTORE with ShellExecuteEx also as "open"
and "explore" lpVerb, but it does not help. For now I do not
understand the logic behind this windowed versus desktop mode.
I realise the outlook is grim but, I hope that's of help to someone..
Proof / Evidence
Link to an SFX archive demonstrating this, if anyone wants it:
https://dl.dropbox.com/u/27573003/Social%20Distribution/restart-explorer.exe
You may notice here that I'm running the commands inside a VM (as denoted by
VMwareTray.exe) but it is not a VM-caused conflict. I've tested the exact same
files on my own host system (which is the same OS) and have had the same
results.
Update
I'm experiencing similar "works outside of an SFX archive but not from one"
problems when using REG ADD in a completely different project.
I just don't think SFX archives play nice with batch files.
I think user1631170 is on to something, "I wonder if some part of Win-RAR is running in 32-bit mode? Could you even start explorer64 running from a 32-bit process? I am pretty certain that Windows won't do that."
When I start explorer.exe from ProcessHacker (32-bit process manager), I get an explorer window.
But I can force it to start the 64-bit explorer with this:
%systemroot%\sysnative\cmd.exe /c start /B explorer.exe
sysnative is a keyword that Windows recognizes to bypass the file system redirection for 32-bit/64-bit (http://msdn.microsoft.com/en-us/library/windows/desktop/aa384187(v=vs.85).aspx
Enjoy!
I had this same problem and found that all the solutions here still didn't work from a batch script.
None of these worked completely:
start explorer.exe
start explorer
explorer.exe
explorer
because they all either opened a window (and didn't show the taskbar again), or the batch script then hung thereafter and couldn't execute any more commands
I found that this line in the batch file did work (after killing explorer.exe):
start "" "%windir%\explorer.exe"
and also allowed other commands to be executed after it in the script
This works in Windows 7:
taskkill /f /IM explorer.exe
start explorer.exe
exit
For restarting explorer.exe, this worked for me.
powershell.exe Stop-Process -processname explorer
When you run explorer.exe from an 32-bit application in 64-bit windows, the path will be redirected to the SysWOW64 directory which contains the 32-bit explorer.exe.
In XP64 it wasn't not such a big deal. In the taskmanager you can see the 32-bit explorer.exe running but it did start as the shell. In Windows 10 (as I came to this problem, it looks like it is introduced in Windows 7), the 32-bit explorer.exe is a stub which creates a new instance of the 64-bit explorer.exe. It probably passes a path on the commandline here so the 64-bit explorer.exe opens a window instead of starting the shell.
So it is still like before that you can control whether a window or a shell should be started by starting explorer.exe with or without a path as commandline parameter.
Instead, you should force starting the 64-bit explorer.exe from the 32-bit application and all is ok. To do this, one method is using the sysnative directory as mentioned above. But another method is to use Wow64DisableWow64FsRedirection/Wow64RevertWow64FsRedirection.
I did the latter and can confirm it works nicely. For both CreateProcess and ShellExecuteEx API.
Try
%windir%\explorer.exe
start %windir%\explorer.exe
start /d%windir% explorer.exe
I have seen similar problems before doing this in C#. The process had to be invoked by calling explorer shell rather than explorer window, but I haven't had any problems in batch.
Try using this:
taskkill /im explorer.exe /f
explorer
The difference between the other answers being explorer rather than explorer.exe which has caused problems before for me.
This works on my Win7 x64 PC.
Hope this helps!
The other day, I was having a look through some of WinRAR's more advanced options and came across this tab:
As soon as I saw that I suspected it to be part of the problem and solution, as this issue only ever occurs on Windows 7 x64.
As suspected, using the Default64.SFX module instead of the default Default.SFX module entirely fixed the issue. Finally.
I do not understand why, but it will only for me if using the full path, regardless of your PATH variable.
%windir%\explorer
Have same issue with Visual Studio.
What works for me (Win 7 Pro 64bit):
PPM on Project name select "Properties"
Configuration Properties > Build Events > Pre-Build Event
taskkill /im explorer.exe /f
Configuration Properties > Build Events > Post-Build Event
start "" "C:\Windows\explorer.exe"
But this make other problem (the IDE is frozen after the explorer runs) and now I'm only able to restart the IDE to run build command again...
Use this (.bat with administrative privileges) in x64 or x86
tasklist /fi "imagename eq explorer*" | find /i "explorer*"
if not errorlevel 1 (taskkill /f /im "explorer*") else (
start %windir%\explorer.exe
What worked for me in Windows 7 64 bit was
"C:\Windows\expstart.exe"
or just
expstart.exe
Try adding a explorer.exe key to App Paths in the registry.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\explorer.exe
(Default) C:\Windows\explorer.exe
Path C:\Windows
or copy the following to notepad and save it as a .reg file then run it:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\explorer.exe]
#="C:\Windows\explorer.exe"
"Path"="C:\Windows"
To see the start panel you need to execute the explorer.exe from the system32 folder
taskkill /im explorer.exe /f
cd %WINDIR%\system32
start %WINDIR%\explorer.exe
Easy Context Menu
Just right-click on the desktop and choose Restart Windows Explorer. Enjoy!

Resources