Mount SMB-shares from Hudson's job: ERROR 1326 - windows

In the building system I use some script that copies files from a network drive to the Hudson's workspace by using SMB. Then performs decompression it and deletes the old files.
net use \\NET_DRIVE\ipc$ /user:admin password
robocopy \\NET_DRIVE\SharedFolder/ C:\Users\user\.hudson\jobs\ais\workspace vendor.7z>nul
net use \\NET_DRIVE\ipc$ /D
cd "C:\Users\user\.hudson\jobs\ais\workspace">nul
rd /s /q "C:\Users\user\.hudson\jobs\ais\workspace\vendor\">nul
7za x vendor.7z>nul
del vendor.7z>nul
When I execute this script from Windows command line, everything works and I get my archive. But when I use it in the pipeline, I get error 1326:
Logon failure: unknown user name or bad password
I added the remote domain to the script so that the Windows had not invoked a local account, but it didn't help. I decided to run the command which mount network drive "manually":
net use \\NET_DRIVE\ipc$ /user:admin password /persistent:yes
Then the script a little bit reduced and became working:
robocopy \\NET_DRIVE\SharedFolder/ C:\Users\user\.hudson\jobs\ais\workspace vendor.7z>nul
rd /s /q "C:\Users\user\.hudson\jobs\ais\workspace\vendor\">nul
7za x vendor.7z>nul
del vendor.7z>nul
But I would like to be able to mount SMB-shares from the Hudson's job. How to do it?

Hudson's/ Jenkin's service or servlet- container where it deployed should be run with administrator's privileges.

Related

How to delete the contents of temp folder in remote machine through command

I have a requirement where i need to delete the contents of the temp folder on number of remote windows machines.
i tried below wmic command to delete
WMIC /node:...** /user:xxxx /password:xxxx path cim_datafile WHERE "path='%Winddir%\temp*.tmp' AND Extension ='tmp'" delete**
But it throws an error saying
ERROR:
Description = The RPC server is unavailable.
Please suggest me a way to delete temp folder contents on remote machine.
Most simple way - if you're not strictly forced to use WMI, you can do that with psexec:
PsExec.exe \\<computer> cmd /c "rmdir /s /q %windir%\temp\"
or, if you're not logged into domain admin or global workstations admin account -
PsExec.exe -u <user> -p <password> \\<computer> cmd /c "rmdir /s /q %windir%\temp\"
If should not completely delete the folder since Windows keeps some files open and locked inside it, but anything not read-only or locked would be deleted, both files and folders.
Then, to do this with a list of computers, just use a cmd file like this (list.txt contains just computer names/ips, without \:
for /F %%s in (list.txt) do (
echo %%s
start "" /min PsExec.exe \\%%s cmd /c "rmdir /s /q %windir%\temp\"
)
Start command makes all psexec processes run in parallel and minimized so you don't have to wait for each computer to finish before starting another
psexec.exe is a part of sysinternals package from M. Russinovich, I'd like to leave a direct link but don't know if it's permitted or not.
I think it should be able to connect to remote pcs if you have access to file shares and remote computer management (and admin rights of course)

Cannot run a batch code as admin privilege

I am using a batch code in removal Disk to install some software (from removal Disk).
My Problem is I need to run this batch code as administrator , but when I ran it as administrator it ran from C:\Windows\system32 but my installer path is different.
This is a sample script :
Setup1.exe /S
Setup2.exe /S
Now how can I change the directory to installer path after run as admin
As per my comment:
You can either add the following to the top of your batch script:
#CD /D "%~dp0"
…or prefix your setup file like this:
"%~dp0setup.exe" /S

Cannot fully delete ProgramData from Windows 8 installation within WinPE

I have a script that runs in WinPE that takes a system drive with Windows installed and deletes everything off of the drive (keeping the filesystem intact).
When dealing with a Windows XP/Vista/7 installation it functions properly. attrib -S -A -H -I -R /S /D \ is run, and then everything is deleted.
However, within Windows 8, I run into an "Access Denied" error. For some reason, even as the SYSTEM user within WinPE, I can't edit the directory C:\ProgramData\Microsoft\Windows\LocationProvider. I can't use attrib to set attributes, I can't delete it - I can't even cd into it! dir /a just returns File Not Found.
Using rmdir /S /Q gives me the "Access Denied" error.
Assuming that the problem is related to permissions and/or ownership, you can work around it using the built-in robocopy tool - luckily, this is included in Windows PE.
First, create an empty directory, e.g., x:\empty and then run
robocopy /e /purge /b x:\empty c:\
The /b flag tells robocopy to use backup mode, which bypasses security.
Had the same problem. You need to take ownership first, for example using takeown.exe. Then fix permissions, for example using icacls.exe. Then proceed as you wish with copy, move, delete.

Bat file - Net use from remote desktop not work well in some cases

I try to run .bat file from remote desktop.
I do it by run the next command:
net use m: \\the-ip-of-the-remote-computer mypassword /myuser
// Execution works well
then, I try to xcopy from the remote desktop to my computer. So I write this:
net use t: \\the-ip-of-the-remote-desktop mypassword /myuser
xcopy \\the-ip-of-the-remote-computer my-libary
But in some cases, this command is not execute well.
I also try this, and it doesn't work:
net use m: \\the-ip-of-the-remote-desktop mypassword /myuser
xcopy net use t: \\the-ip-of-the-remote-computer mypassword /myuser my-libary
and It also doesn't work.
What can be the problem.
Try mapping the share, then change to that drive before using xcopy
net use M: \\the-ip-of-the-remote-computer mypassword /myuser
pushd M:\
xcopy folder\filetocopy C:\yourcdrivefolder

CMD command not working?

When i am running the command below on a folder on Desktop, it is working fine
cacls folder_name /e /p everyone:n
But, when i am trying to do the opposite on same folder i.e
cacls folder_name /e /p everyone:f
this is giving "Error : Access is Denied"
Why this is happening ?
Are you running your command terminal as admin? The best explanation for this is that you do not have full control on this folder for the user you are running under, so you cannot grant this privilege to others.

Resources