How we can delete particular folders and sub-folder that were open by other user in network share when other client machine open the share path having the write access to that folder.. psfile and net files command will close the file session of client machine but again after few seconds(1-2) it will create automatically another session for that user in server...
do we have any batch command to permanently kill the session of all connection in a particular shared path?
Following is the command i use in net files but this shows the process will create again within 2 seconds after killing it.
for /f "skip=4 tokens=1" %a in ('net files') do net files %a /close
the above command will close the session but immediately after 1-2 seconds another session will be created
Try this,
openfiles /Disconnect /s host /OP "path\to\file.exe" /ID * /u "username" /p "password".
Explain comand:
openfiles /disconnect
Enables an administrator to disconnect files and folders that have been opened remotely through a shared folder.
/disconnect -> to close the file.
/s -> host from file, exemple: 192.168.1.10.
/op -> full path of file, exemple: "C:\projects\file.exe" .
/id -> id of process, when you pass "*" is same than all ids.
/u -> user with permission to close file in remote server.
/p -> password from user.
Related
I am running attached script to backup postgresql database by using task scheduler. Script is executed successfully but backup is not happening. Same script i have run on powershell and it's working fine.enter image description here
I want to schedule daily backup on windows server. Please help me or suggest any alternative to automate the backup.
Regards
Sadam
Try this script, it will create a backup file with a name consisting of a timestamp:
First, create a backup.bat file and just run it (set your credentials and database name):
echo off
echo 'Generate backup file name'
set CUR_YYYY=%date:~10,4%
set CUR_MM=%date:~4,2%
set CUR_DD=%date:~7,2%
set CUR_HH=%time:~0,2%
if %CUR_HH% lss 10 (set CUR_HH=0%time:~1,1%)
set CUR_NN=%time:~3,2%
set CUR_SS=%time:~6,2%
set BACKUP_FILE=%CUR_YYYY%-%CUR_MM%-%CUR_DD%_%CUR_HH%-%CUR_NN%-%CUR_SS%.custom.backup
echo 'Backup path: %BACKUP_FILE%'
echo 'Creating a backup ...'
set PGPASSWORD=strongpas
pg_dump.exe --username="postgres" -d AdventureWorks --format=custom -f "%BACKUP_FILE%"
echo 'Backup successfully created: %BACKUP_FILE%'
As a result, you should see such a picture, and a file with the extension .custom.backup should appear in the directory
If you get an error that the executable file "pg_dump.exe" was not found, then specify the full path to this file, something like "C:\Program Files\PostgreSQL\12\bin\pg_dump.exe", or add a directory with binaries PostgreSQL to environment variables (more details here)
-
To schedule regular execution, you can use the windows task scheduler
Press win + r and enter taskschd.msc
Select Create Basic Task
Then follow the steps of the wizard, specify the schedule, and in the "Action" section, specify "Start a program" and then the path to the backup.bat file
To check that everything is correct, find the task in the list and select Run
You can read more about Postgresql backups on Windows here
Basically just attempting to create a very basic program that will display the last modified date of a file on our server. Problem is I have no idea how to write it. This is what I attempted
cd \\Server\Folder
msg dir
I also ran into the problem "CMD Does not support UNC Paths as Current Directories" when I tried to change the CD to our servers directory.
What I would like it to do is display in a dialog box the modified date of a "Text.txt" located on our server \\Server\Folder
Any and all help is appreciated
Next .bat script should work:
set "_folder=\\Server\Folder"
set "_filename=Text.txt"
set "_filedatetime=N/A"
pushd %_folder%
for %%G in (%_filename%) do (
rem echo %%~tG %%~fG
if not "%%~tG"=="" set "_filedatetime=%%~tG"
)
popd
echo file %_folder%\%_filename% date and time: %_filedatetime%
Note there is no dialog box in pure cmd command line interpreter, try set /P.
Resources:
SET: Display, set, or remove CMD environment variables
PUSHD, POPD: and UNC Network paths
FOR commands
~ Parameter Extensions
I'm trying to copy files from one directory on a server to another server without overwriting permissions at the destination but I'm working with an "interesting" setup:
Server A
Git Server
Jenkins CLI
Server B
Web Server
I have a Jenkins process that will run when my fellow web developers commit changes to our repository. Jenkins then copies the files from the repository into it's workspace (located on the C: drive of the server). Once done downloading the files, I'm executing a command script that uses "ROBOCOPY" to copy the files from a directory in the Jenkins workspace to a network share (located on another server) that is pointed to the IIS web directory.
The ROBOCOPY script is as follows:
ROBOCOPY "C:\...\Jenkins\workspace\dev\app" "\\network-share-to-web-server\app" /mir /m /R:0 /W:1 /MT:8 /V /LOG:WhySkip.txt & if %errorlevel% leq 2 exit 0
Here's the problem: ROBOCOPY will only copy the directory structure and NOT the files within the directories which is all of our HTML/JavaScript/CSS/Images... AKA: The changes that we've done.
Any and all help would be greatly appreciated!
Try without /m (Copy only files with the Archive attribute and reset it)
As you want /MIR (Mirror), let Robocopy choose files to sync
I am trying to gather files/folders from multiple computers in my network into one centralized folder in the command console (this is the name of the pseudo server for this set of computers)
Basically, what i need is to collect a certain file from all the computers connected to my network and back it up in the console.
Example:
* data.txt // this is the file that i need to back up and its located in all the computers in the same location
* \console\users\administrator\desktop\backup\%computername% // i need each computer to create a folder with its computer name into the command console's desktop so i can keep track of which files belongs to which computer
I was trying to use psexec to do this using the following code:
psexec #cart.txt -u administrator -p <password> cmd /c (^net use \\console /USER:administrator <password> ^& mkdir \\console\users\Administrator\Desktop\backup\%computername% ^& copy c:\data.txt \\console\USERS\Administrator\DESKTOP\backup\%computername%\)
any other suggestions since im having trouble with this command
Just use the command copy must easy.
take a look:
for /F %%a in (computerslist.txt) do (
copy \\%%a\c$\users\administrator\desktop\%%a\*.txt c:\mycollecteddata\%%a
)
that will copy all files *.txt for all computers that are on computereslist.txt; the copy will be with the current credentials. Save the code on a file *.cmd and execute with the right user, you can create a scheduled taks to start with a user thant is commom for all computers.
Good work.
I have been playing around with PSTermninalServices for a while, and I was wondering if it's possible to track, or get, the current location of the user that is holding, working directory, a remote desktop sessoin? E.g what folders are open and what files are opened by the user. Is this possible to achieve with scripting like PowerShell?
OS: Windows Server 2008 R2
Best regards.
DA.
i don't know how to do it with PS, but you can use psfile (part of the excellent pstools suite from Mark Russinovich )
psfile.exe [\\RemoteComputer [-u Username [-p Password]]] [[Id | path] [-c]]
-u Specifies optional user name for login to
remote computer.
-p Specifies password for user name.
Id Id of file to print information for or close.
Path Full or partial path of files to match.
-c Closes file identified by file Id.
Omitting a file identifier has PsFile list all files opened remotely.