3

Hi I try to create a folder on local user which doesn't have access right. So the script is to help user creating a folder by using domain admin account and will be converted to EXE when it run. So I figure out using PsExec to use it. But I'm no idea how to combine it with MKDIR. Here is the BAT script.

@echo off
setlocal enableextensions
set today=%date:~10,4%-%date:~7,2%-%date:~4,2%
set todayyear=%date:~10,4%
set todaymonth=%date:~10,4%-%date:~7,2%
set pass_local=adminpass
set path_pskill="\\SERVER\$PROGRAM\PsKill.exe"
set path_psexec="\\SERVER\$PROGRAM\PsExec.exe"
set path_backup=\\SERVER\$WORKSTATIONS\UPGRADE
set path_sourcedrive=C:\Users
set path_source01=AppData\Local\Microsoft\Outlook
set path_source02=Contacts
set path_source03=Desktop
set path_source04=Documents
set path_source05=Downloads
set path_source06=Favorites
set path_source07=Pictures
set path_source08=Music
set path_source09=Videos

subst b: "%path_backup%"
%path_psexec% \\%computername% -u DOMAIN\Administrator -p %pass_local% "cmd /C \"mkdir \"b:\%todayyear%\%todaymonth%\%username%\"\""

subst b: /D

Other simple to understand is:

psexec.exe \\hostname -u DOMAIN\Administrator -p adminpass "cmd /C \"mkdir \"b:\%todayear%\%todaymonth%\%username\"\""

Anyone please can help ?

m.k.frenky
  • 301
  • 2
  • 4
  • 11

2 Answers2

2

Use the below command to create a directory in remote location.

psexec \\\IPAddress -u username -p Password cmd /c mkdir c:\testfolder

Swapnil Gangrade
  • 454
  • 6
  • 12
0

Actually, you're on the right track as long as the login credentials that you're adding is correct, else, you'll receive an access denied error. Also, you may have to place some START /wait timers in the batch script to make sure that the lines before the psexec call get executed first.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Janou
  • 125
  • 1
  • 9