View Local Administrator accounts on a remote computer using Batch - batch-file

Is there a way to remotely view local administrator accounts on remote computers within a network or possibly run NET LOCALGROUP ADMINISTRATORS and have the result be viewed on the command prompt instead of extracting it in a notepad (via psexec)?
Thanks in advance!

Try a Bat file with this.
for /f %%A in (computers.txt) do (echo Identifying group members on "%%A" ...
psexec -s \%%A net localgroup administrators )
Create a txt file with computer names without spaces one name for each line.
Redirect the command to a txt file and creat a log with it.
Ex. batfile > log.txt

Related

Encrypt username and password on batch script

I'm trying to load flat file into server through FTP using batch files. I'm aware of the scripts and I'm able to transfer the file to server. Currently I'm following this below method.
#echo off
title File Transfer
color 3F
cd "C:\Users\username\Desktop\Access\"
echo -
echo - Transferring File to Server. Please be patient...
echo -
echo - Closing this window will Terminate the entire process
ftp -n -s:"C:\Users\username\Desktop\Access\ftp.txt" server_name >"C:\Users\username\Desktop\Access\ftp.log"
Script File Code: (ftp.txt)
User Userid password
mkdir App
put "C:\Users\username\Desktop\Access\File.txt" "App/File.txt"
quit
My requirement is that I should not display username and password on the script file. These credential information dynamically coming from the variables and I'm generating this batch file and script file dynamically.
Kindly any experts suggest me solution which makes more sense to accomplish this requirement. Thanks in advance.
You generally cannot encrypt anything while still allowing it to be decrypted automatically.
See for example BASH: allow users to FTP files to my server without revealing FTP login credentials to them
All you can typically do is to obfuscate the credentials. But the Windows ftp.exe does not allow even that.
With ftp.exe, you can use input redirection to somewhat reduce the risk:
(
echo user %USERNAME% %PASSWORD%
echo mkdir ...
echo put ...
echo quit
) | ftp.exe -n example.com

Need help writing .bat file which changes all file permissions in a folder to Everyone

I appreciate your time so I won't take much of it. Here's what I'm trying to do: I want to create a .bat file that, when executed, will open the Command Prompt program, change directory to a folder (located on the C:), then execute a line of code that will change the file permission status of all files in that folder to Everyone. I intend to create a Windows task that will run this .bat file everyday. I understand how to setup the Windows task, but I can't figure out exactly how the .bat file should be written. Can anyone help?
Here's what I've got so far:
ECHO OFF
[Tab]Start "" C:\Windows\system32\cmd.exe
ECHO OFF
[Tab]Prompt cd cd:\google drive
ECHO OFF
[Tab]Prompt cacls *.* /t /e /g everyone:f
If you're interested, here's why I'm trying to create this .bat file:
I use a single Google Drive account on two file server computers, one in each of two offices. Each office has this file server and about 10 client computers. The client computers access files on the shared Google Drive folder (located on the file server) and occasionally add/edit/delete files. Google Drive does a great job of keeping all files synced between the two offices, but one problem I have is that if office A adds a file, the only computer in office B that can see it is the file server. I have to change the file permission to "Everyone" using the file server in office B before any of the client computers in office B can see the file. Over time, it's become very annoying to manually change the file permission every day and I'm looking for a shortcut. Please let me know if you can think of a better one.
If you got the commands right then this is a batch script with them.
The && will run the following command only if the cd command was successful.
#echo off
cd /d "c:\google drive" && cacls *.* /t /e /g everyone:f

not able to delete file from command line in windows server 2008

I am writing a batch program in windows server 2008
I am using robocopy command and /move parameter to copy and delete the file from source path. Not able to succeed.
Then I tried using DEL dos command. Not successful.
Throwing access error
Could you please let me know the dos command to forcefully delete a file or clear the contents of the file.
assuming the file is write-protected, try:
del /f file
Sounds like you don't have permission to that file/folder. Even if you are an admin... open an administrative Command Prompt by Right Clicking on CMD.exe or shortcut and 'Run as administrator'.
AN administrator does not have the same privileges as THE local Administrator.

How to make a popup while windows session is locked (prefer Windows BATCH file)

I am Help Desk for a company and we have some computers on our VPN. We sometimes have to use Windows Remote Desktop to login to these computers. (mostly Windows XP but some Windows 7)
When we remote into a Windows the computer/session is locked
I would like to be able to make a popup appear on their computer saying they can log back in.
I use 2 command-line tools in order to issue remote commands: psexec & nircmd.
nircmd is useful because it has command-line options to make a pop-up but it will pop-up inside the session not on the "computer locked screen".
I have played with Local Security Policy and it will you to display a message when they first login but not while the session is locked.
It does have an option to display username while session is locked so somehow it can display certain things during a locked session.
#npocmaka Thanks
I ended up using msg.exe but because of restrictions on our company's network I used a combination of psexec and msg
msg server:IPADDRESS /v "message"
didn't work so I used
psexec \IPADDRESS -u username -p password msg /server:IPADDRESS /v "message"
but in order for it to work I had to run
psexec \IPADDRESS -u username -p password reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v AllowRemoteRPC /t REG_DWORD /d 1 /f
on the remote computer. I got the reg command from another post in StackOverflow actually!

Check remote file existence on multiple Windows servers

I need to check a file status (existing? or last modified date) on multiple remote Windows servers (in LAN). The files are accessible via UNC path. The remote PCs need a user name and password. It's best to be some sort of script.
I am not system admin, but asked to do this by my boss because each of these PCs are host of SQL Server and the file is a backup of database. I am a SQL Server database developer. I was trying to do it using T-SQL, but just found it not geared to do this (although maybe doable).
Create a batch file like (say check.bat):
#echo off
set list=server1 server2 server3 server4 serverN
for %%s in (%list%) do (
echo Logging in to %%s
net use \\%%s\shared /user:mydomain\myuser password
echo Checking file existence on %%s
if exist \\%%s\shared\file.txt (
echo File exist on %%s
) else (
echo File does NOT exist on %%s
)
echo Logging out
net use \\%%s\shared /delete
)
For details on the net use commands, see the accepted answer for question Mapping a network drive without hardcoding a drive letter in a batch file.

Resources