Is there a Windows command to close a file? [closed] - windows

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I have opened a file through on Windows command prompt, just by navigating to that directory and then typing it's name. Now is there a way to close that (open) file through the command prompt? I've been searching around and I can't find out how. Seems to be a pretty simple command to not exist.

There is no MS-DOS in Windows and has not been since about 2003. The "Command Prompt" program (named cmd.exe) runs in a console window and looks and behaves like the command interpreter of MS-DOS, enough like it to seem the same to many people, although there are some small differences.
If you give a filename as a command to a command prompt and that named file is not a program, it looks at the extension to try to select an appropriate program to run and open the file. The .doc extension usually corresponds to MS Word (Office) or the stripped-down version MS Works, but depending on what software you have installed and how it is configured .doc could be something else. You can find out what it is on your system by the command-prompt commands assoc .doc and usually then ftype (value from assoc) or by looking in the registry under HKEY_CLASSES_ROOT. Once the program runs (a running program is also called a process) it may keep the file open while running (like Word) or only open it briefly and then close it (like notepad).
Once you know what program/process is running, you can direct that process to stop with the taskkill command. Type taskkill /? for help information. If there is more than one process running the same program and you use the /im option, it will stop all of them, not just the one you want. To use the /pid option, tasklist or TaskManager can help you find the right process -- but if you use TaskManager it can also stop the process, so taskkill is unnecessary. If the program malfunctions and doesn't stop when directed, taskkill /f will force it, but this may leave the open file(s) with damaged and incorrect or unusable data.
Also note that command itself effectively keeps the directory open. If you are trying to rename or move a subtree of files including that directory, you must first either cd the command process somewhere else, or terminate it with exit.

Related

Enabling/disabling a device in Windows 10 from command line [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I have a specific piece of hardware which I'd like to disable and re-enable each time my Windows restarts. I created a batch script which is supposed to do that, along with running my program afterwards:
cd %~dp0
devcon.exe disable "PCI\VEN_1002&DEV_687F"
timeout /t 3
devcon.exe enable "PCI\VEN_1002&DEV_687F"
runMyWindows.exe --totally-not-virus
I am not sure if devcon.exe is a proper application for this in the first place because I have no experience with writing Windows scripts at all.
However, I have noticed that those commands don't quite do the job because my runMyWindows.exe program doesn't work as it should until I go to Windows Device Manager and manually disable and re-enable this device.
I have only 1 user on this machine which is in "Administrator" group and I am not running this script in any special way except double-clicking the .bat file, or in case of the restart, it is run from the startup folder (C:\Users\oxxo\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup).
Is there a way to do this properly within my batch script which should be run automatically on Windows startup?
PnPUtil do this job also and no SDK or anything else related required to download.
Included in Windows since Vista:
https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/pnputil
Examples
Disables device specified by device instance ID:
pnputil /disable-device "USB\VID_045E&PID_00DB\6&870CE29&0&1"
Enables device specified by device instance ID:
pnputil /enable-device "USB\VID_045E&PID_00DB\6&870CE29&0&1"
Most people who'll be reading this thread won't find the other answer very useful, because it's mostly about how to run the script in the question with administrator privileges. I'll attempt to answer the implicit questions here:
Enable/disable a device via the command line
I found it easiest to use devcon.exe (6mb), like in the question:
set HARDWARE_ID="PCI\VEN_8086&DEV_4229&SUBSYS_11018086&REV_61"
devcon disable %HARDWARE_ID%
timeout /t 3
devcon enable %HARDWARE_ID%
devcon.exe requires administrator privileges.
Where to get devcon?
It's part of the Windows driver development toolkit. Unfortunately, the official resources ask you to download a 1gb SDK. I was able to get around that by following one of the answers here: https://superuser.com/questions/1002950/quick-method-to-install-devcon-exe
Once you have it, make sure devcon.exe is on your %PATH%. I put mine in C:\Windows\System32\.
Find the hardware ID of the device you want to manipulate
Open a Command Prompt with administrator privileges and do devcon hwids *, which will print all the devices and their corresponding IDs. That will produce a lot of output. Use Command Prompts search function to find what you need. Here's the section I was interested in:
PCI\VEN_8086&DEV_4229&SUBSYS_11018086&REV_61\4&6AB551C&0&00E1
Name: Intel(R) Wireless WiFi Link 4965AGN
Hardware IDs:
PCI\VEN_8086&DEV_4229&SUBSYS_11018086&REV_61
PCI\VEN_8086&DEV_4229&SUBSYS_11018086
PCI\VEN_8086&DEV_4229&CC_028000
PCI\VEN_8086&DEV_4229&CC_0280
Compatible IDs:
PCI\VEN_8086&DEV_4229&REV_61
PCI\VEN_8086&DEV_4229
PCI\VEN_8086&CC_028000
PCI\VEN_8086&CC_0280
PCI\VEN_8086
PCI\CC_028000
PCI\CC_0280
Pick a specific enough ID and check if it works by doing:
devcon find "PCI\VEN_8086&DEV_4229&SUBSYS_11018086&REV_61"
If that finds only 1 device, and it's the one you want, you're good. Notice that often you'll want to escape the hardware ID with quotes.
Bonus: running a .bat script at startup or power on
In my case, I also needed to run this script when computer has booted after shutdown or sleep. I gave the above script sensible permissions and used Task Scheduler to run it on login and on startup, in its terminology:
https://www.sevenforums.com/tutorials/67503-task-create-run-program-startup-log.html?ltr=T
Due to security 'improvements' in Windows 10 and certainly since Windows Vista and the introduction of User Account Control I assume you would need to Run as administrator, not just be a member of the Administrators group.
It should generally be read that Run as administrator means Run as the user with the account name Administrator not Run as any user who holds membership of the Administrators group.
To Run as administrator, right click on the batch file and select Run as administrator from the context menu.
There are other ways of running as Administrator too.
You can use a self-elevating batch file, which usually uses a PowerShell or WSH helper function.
You can use Task Scheduler and choose the appropriate triggers and account information, (possibly using the SYSTEM account).
Additionally you need to ensure that DevCon.exe is either:
Along side the batch file, "%~dp0DevCon.exe" Disable "PCI\VEN_1002&DEV_687F*"
At a location defined within %PATH%, DevCon Disable "PCI\VEN_1002&DEV_687F*"
Invoked using its full path, "C:\Tools\DevCon.exe" Disable "PCI\VEN_1002&DEV_687F*"
In all cases above please note the asterisk which is missing from your examples

Why this occur about hidden files [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I've found 2 hidden files on my drive D:/ , I found them by accident, because one day I opened a picture (1 picture exactly on my drive D:/), and by accident I push right navigation button on keyboard, and there is another picture WHICH familiar with me, and there is another, okay maybe this is not important but this is the name (1. AlbumArtSmall.jpg, 2. Folder.jpg), okay I think these 2 jpg files is hidden, but when I unhidden by the step : Tools > Folder Options > View > Show hidden files and folders, but It doesn't make sense (there is no such file on D:/), after that I check it again by command prompt, which is the step :
1. %drive% d:
2. D:> dir
3. there is no such file (those 2 jpg file)
But, when I check with cygwin terminal as I know this is for Linux OS (my OS is windows7 by the way :
1. /cygdrive/d
2. $ dir
3. there is such file (those 2 jpg file)
I know this is not a big problem, but I'm curious why this is happened? And if I want to delete these 2 files, I can do nothing, maybe there is a way to delete them by cygwin terminal command, but the problem for me not because I want to delete them, but more for why this is occur?
Thanks in advance, sorry for my English.
They are probably hidden and system. You can display them in explorer by selecting, in addition to "show hidden files", the "show system files" option.
On the command line, dir /a will show you hidden and system files, too. To delete them from the command line, type attrib -h -s -r *.jpg to remove hidden, system, and readonly attributes from all jpg files (for example). Then just normal del file.jpg.
Cygwin does not recognize windows-like hidden files (thus showing you them), because in Linux hidden files are marked with a leading point. If you use a windows shell on "unix-"hidden files, you will see them, too, but cygwin should not.
For deletion: Afaik you can make them visible and then simply delete them.
Command prompt won't show hidden files if you execute dir. If you want to see these hidden files, then use dir /a.

Robocopy Crashed trying to delete very long(1000+) subfolders WINDOWS [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I'm using the robocopy command
robocopy empty_dir super_subfoldered_folder /s /mir
rmdir empty_dir
rmdir super_subfoldered_folder
to delete the folders at once but during this command robocopy.exe stops working.
I have tried to delete from a path that starts at least 50 sub folders inside the main folder still crashes.
I've tried renaming them to "1" but windows doesn't let me past 100+ folders and there are at least 1000 more. Tried to create new partition- subst j: . rename some folders and delete the partition but this takes forever because of their number.
Tried dir /x and del the shortened name -> doesnt work.
Is there another way to delete those folders ?
File path in Windows goes through several layers before it gets to the actual file system driver. As a result there are two limits. 1) MAX_PATH (260) limitation introduced by the top-level API 2) 32K actually used by the file system. Since you already have that path, it is obviously within the limits of the file system. Try using path by adding "\\?\" to the front. This is an indicator that Win32 API should not parse the string but pass it directly to the file system (http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx). This will only work if the proces making the call is Unicode and 64-bit (on a 64-bit system). Otherwise the string must be converted and/or marshaled and you are back to the 260 limit.
Windows has a subdirectory depth limit and it's not very deep.
You may get a better result by booting up a Live Linux distro on cd or USB, like Ubuntu, and using the GUI file manager to delete the tree.

How are windows programs installed? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
This looks like a common question. But I was not able to find answer for it. When we try to install windows programs, what exactly happens? What files are copied where? What is written in the registry?
Most programs come with an installation program named Setup.exe or Install.exe. When you install a program, the installation program usually does the following:
Looks for a previous version of the program on your hard disk. If it
finds a previous version, the program may ask whether you want to
replace the previous version.
Creates a folder in which to store the program files. Most
installation programs ask where you'd like this folder. Some
installation programs also create additional folders within this
folder. Windows creates a folder named Program Files, usually in C:\
(if Windows is stored in a partition or drive other than C, the
Program Files folder is usually in the same partition). We recommend
you install all your programs in folders within the Program Files
folder.
note Some software vendors have the bad habit of installing
application programs in locations other than your Program Files
folder. You can't do much about this; the additional folders may
clutter up your root folder, but they don't do any harm.
Copies the files onto your hard disk. If the program files are
compressed, the installation program uncompresses them. Usually, the
installation program copies most of the files into the program's
folder, but it may also put some files into your C:\Windows,
C:\Windows\System, or other folders.
Checks your system for the files and hardware it needs to run. For
example, an Internet connection program might check for a modem.
Adds entries to the Windows Registry to tell Windows which types of
files the program works with, which files the program is stored in,
and other information about the program.
Adds a command for the program to your Start | All Programs menu
(some programs add submenus to the Start | All Programs menu to
contain several commands). The installation program may also add a
shortcut to your Windows desktop to make running the program easy for
you. You can change the position on the Start menu of the command for
the program, get rid of the command, or create a command if the
installation program doesn't make one. You can also create a shortcut
icon on the desktop, if the installation program hasn't done so, or
move or delete the program's shortcut.
Asks you a series of questions to configure the program for your
system. The program may ask you to type additional information, like
Internet addresses, passwords, or software license numbers. It may
also ask which users should be able to run the program.
Every installation program is different, because it comes with the application program, not with Windows. If your computer is connected to a LAN or to the Internet, the installation program may configure your program to connect to other computers on the network.

Overcoming "It is being used by another person or program." [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Is there a way to unlock Windows files without downloading a utility?
I have a few files on my Windows XP C: drive that are very old and very useless. When I try to delete these files I get the following message:
Cannot delete FILENAME.zip: It is being used by another person or program
Close any programs that might be using the file and try again.
No one is accessing this file. No program is using it currently. Windows has screwed up the file locking mechanism.
Is there a way to delete this file without downloading someone's unlocking utility? I find the sites offering these programs to be a tad sketchy.
How could you force the file to unlock from within a program? I'm competent in Java, Perl, and Ruby, but I haven't seen anything among their libraries that would aid me here.
I've successfully used Process Explorer to find out which process has the file open. It saves a reboot that may not fix the problem anyway.
In process explorer: Find > Handle or DLL... then search for the name of the folder/file, then double click one of the search results. It'll select a handle in the main window, which you can right click and close.
Try downloading "Unlocker". Google it and take my words that it doesn't have any worm/spyware/virus. It is pretty cool utility and works great. Give it a try.
Did you try the commandline command OpenFiles
It is built in (XP and above I believe) and has several arguments that can be passed in.
Use msconfig and start up with everything turned off.
Then try to move / delete the file.
Or you can always boot up in safe mode and delete it.
You do that by hitting f8 when the machine boots up.
If you reboot and the files are still locked, then there is some process on your machine that is still using them. First you should figure out what that process is and determine if the files really aren't used any more or not.
Rebooting to Safe Mode is often a very easy way to do it. When you boot in safe mode, it won't load all the stuff set to run on startup. Press F8 while it's booting to access the boot menu, and choose "safe mode".
I had a .jpg pfile that hasd that issue and I couldn't delete. That brought me to this thread. When nothing else worked I renamed the file and left off the .jpg. THEN I could delete it easily. Not sure why, but worked for me
You don't need any utility.
Just use Win32 api to unlock them (simply close the handle)

Resources