Jump to content

small batch to delete folder and desktop shortcuts


Recommended Posts

Posted

I'm really bad at batch/scritps etc.

 

I need to make a small batch that can delete a folder C:\games\counter-strike

And the desktop shortcuts that the game is making.

 

this will delete the folder:

 

rd /s /q c:\Games

 

del /q "Nameofprofil"\desktop"nameofshortcut".ink

 

But it will not delete the shortcut.

 

Its probably pretty easy, so can some one help me out. :)

 

Thanks

Posted

The format for the shortcut deletion should be

 


Del C:\Users\Public\Desktop\ShortcutNameHere.lnk
[/Code]

 

Assuming you are on Windows Vista or later and the shortcut is on the Public profile.

 

Note that shortcuts usually have the extension LNK (as in link without the i).

Posted (edited)

The correct path to the shortscuts are

 

c:\users\Bruger\Desktop

 

but when I use it in the batch it can't find it.

@echo off

 

rem rd /s /q c:\games

del /q "c:\users\bruger\desktop\cs dedicated server cli.ink"

 

Could not find "c:\users\bruger\desktop\cs dedicated server cli.ink"

press any key to continue...

 

I also tried with "public" still can't find it.

Edited by denmyos
Posted
Try Lnk instead of ink. :)

 

HAHAHA as i said,, I suck at batch..it works now..:)

thanks

 

Oh I misunderstood your explanation.

Note that shortcuts usually have the extension LNK (as in link without the i).

 

Don't know how it can be misunderstood, it's quiet clear.

 

Sorry. :)

Posted

I ended up doing this,,, really simple, but it seems to work.

 

@echo off

 

 

rd /s /q C:\Games

 

 

del /q "C:\users\Bruger\Desktop\CS Dedicated Server CLI.Lnk"

 

 

del /q "C:\users\bruger\Desktop\Counter-Strike WaRzOnE.Lnk"

 

 

del /q "C:\users\bruger\Desktop\CS Dedicated Server GUI.Lnk"

 

 

del /q "C:\users\bruger\Desktop\Half-Life WaRzOnE.Lnk"

 

 

 

 

del /q "C:\users\administrator\Desktop\CS Dedicated Server CLI.Lnk"

 

 

del /q "C:\users\administrator\Desktop\Counter-Strike WaRzOnE.Lnk"

 

 

del /q "C:\users\administrator\Desktop\CS Dedicated Server GUI.Lnk"

 

 

del /q "C:\users\administrator\Desktop\Half-Life WaRzOnE.Lnk"

Posted
HAHAHA as i said,, I suck at batch..it works now..:)

thanks

 

Oh I misunderstood your explanation.

Note that shortcuts usually have the extension LNK (as in link without the i).

 

Don't know how it can be misunderstood, it's quiet clear.

 

Sorry. :)

 

No worries, all part of being human. :) Glad it's working. :)

 

If I need to have it to work on all users how should i change it.?

 

Sorry, I was out in a field pulling cables of all things. Although you have an answer, another way would be doing it like this if you have multiple profiles...

 

del /q /S "C:\users\CS Dedicated Server CLI.Lnk"
del /q /S "C:\users\Counter-Strike WaRzOnE.Lnk"
del /q /S "C:\users\CS Dedicated Server GUI.Lnk"
del /q /S "C:\users\Half-Life WaRzOnE.Lnk"

 

To which you would get the following response.

Deleted file - C:\users\administrator\Desktop\CS Dedicated Server CLI.Lnk
Deleted file - C:\users\administrator\Desktop\Counter-Strike WaRzOnE.Lnk
Deleted file - C:\users\administrator\Desktop\CS Dedicated Server GUI.Lnk
Deleted file - C:\users\administrator\Desktop\Half-Life WaRzOnE.Lnk
Deleted file - C:\users\Bruger\Desktop\CS Dedicated Server CLI.Lnk
Deleted file - C:\users\Bruger\Desktop\Counter-Strike WaRzOnE.Lnk
Deleted file - C:\users\Bruger\Desktop\CS Dedicated Server GUI.Lnk
Deleted file - C:\users\Bruger\Desktop\Half-Life WaRzOnE.Lnk

 

As well as it being deleted from any other local profiles subdirectories. :)

Posted

Thanks, it work beautifully. :)

 

Can it be more advanced.?

 

I was thinking if it possible to have the batch report back to a log file on my "server".

It should report back with confirmation that the files were delete and on which computers the files was delete on.

 

:)

Posted (edited)
Thanks, it work beautifully. :)

 

Can it be more advanced.?

 

I was thinking if it possible to have the batch report back to a log file on my "server".

It should report back with confirmation that the files were delete and on which computers the files was delete on.

 

:)

 

You could add the following to the end of the line which will output to a text file named after the computer name to the server with the responses. :)

 

[b]
 >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt[/b]

 

In example...

 

del /q /S "C:\users\CS Dedicated Server CLI.Lnk"[b] >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt[/b]
del /q /S "C:\users\Counter-Strike WaRzOnE.Lnk" >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt
del /q /S "C:\users\CS Dedicated Server GUI.Lnk" >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt
del /q /S "C:\users\Half-Life WaRzOnE.Lnk" >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt

 

(Note: %ComputerName% is a Environment variable that will be auto populated with the Computer Name. :))

Edited by DJ-1701
Noticed a /code tag was missing.
Posted

@echo off

 

 

rd /s /q C:\Games

 

 

del /q /s "C:\users\CS Dedicated Server CLI.Lnk" >> \\xxx.xxx.xxx.xxx\z:\%ComputerName%.txt

del /q /S "C:\users\CS Dedicated Server CLI.Lnk" >> \\xxx.xxx.xxx.xxx\z:\%ComputerName%.txt

del /q /S "C:\users\Counter-Strike WaRzOnE.Lnk" >> \\xxx.xxx.xxx.xxx\Z:\%ComputerName%.txt

del /q /S "C:\users\CS Dedicated Server GUI.Lnk" >> \\xxx.xxx.xxx.xxx\Z:\%ComputerName%.txt

del /q /S "C:\users\Half-Life WaRzOnE.Lnk" >> \\xxx.xxx.xxx.xxx\z:\%ComputerName%.txt

 

 

 

 

pause

 

I ran into a little snag.

I of cause get a Logon failure: unknown user name or bad password.

 

I tried

del /q /S "C:\users\Half-Life WaRzOnE.Lnk" >> \user:"username" "password"\\xxx.xxx.xxx.xxx\z:\%ComputerName%.txt

 

but that didn't work.?

Posted

The share name won't be z:, as a : isn't allowed in a share name.

If you have a Z:\ mapped on your PC though, you could just use Z:\%ComputerName%.txt instead of \\ServerNameHere\ShareNameHere\%ComputerName%.txt

 

If not, I assume the user you are running it as doesn't have access rights to the shared folder on the server?

 

You could use the first bold line below at the beginning of the script to give access. Then the last bold line to remove access.

 

[b]net use \\ServerNameHere\ShareNameHere /user:DomainNameHere\UsernameHere PasswordHere
[/b]del /q /S "C:\users\CS Dedicated Server CLI.Lnk" >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt
del /q /S "C:\users\Counter-Strike WaRzOnE.Lnk" >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt
del /q /S "C:\users\CS Dedicated Server GUI.Lnk" >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt
del /q /S "C:\users\Half-Life WaRzOnE.Lnk" >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt
[b]net use \\ServerNameHere\ShareNameHere /d
[/b]

Posted

I'm sorry i'm not very good at this.

I have no DNS so i use the ip instead.

I'm also in a workgroup, called workgroup

I put the admin username and its password

I'm still confused about the sharename my share is called \\xxxx\f

 

net use \\xxx.xxx.xxx.xxx\xxxx\f /user:workgroup\admin username xxxxxxx

del /q /S "C:\users\CS Dedicated Server CLI.Lnk" >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt

del /q /S "C:\users\Counter-Strike WaRzOnE.Lnk" >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt

del /q /S "C:\users\CS Dedicated Server GUI.Lnk" >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt

del /q /S "C:\users\Half-Life WaRzOnE.Lnk" >> \\ServerNameHere\ShareNameHere\%ComputerName%.txt

net use \\ServerNameHere\ShareNameHere /d

 

 

With this i get a "the system cannot find the file specified.

System error 53 has occured.

The network path was not found.

Logon failure:unknown username or bad password.

Posted

Ah if that's the case then, change workgroup to the the IP address of the server. :)

 

So for example:

net use \\192.168.0.2\f /user:192.168.0.2\admin P@ssword

Posted

sorry.. i had to attend a wedding, which took most of the sunday to get over. :)

 

Sorry, but I don't get it.

 

When I use this in a browser

 

\\xxx.xxx.xxx.xxx

I get prombt for a user name and password,, I then use the same user name and password as my batch,, and it works.

 

BUT in my batch i use this line

 

Net use \\xxx.xxx.xxx.xxx\f /user:Admin P@ssword

But I get a Logon failure: unknown user name or bad password

 

I also tried

Net use \\xxx.xxx.xxx.xxx\f /user:xxx.xxx.xxx.xxx\Admin P@ssword

 

but get the same Error

But I get a Logon failure: unknown user name or bad password.

 

Any idears?

Posted
Only thing I can think of off the top of my head, is that if your share f is actually a hidden/admin share... which would make the share name f$ instead.
Posted (edited)

And the confusion is endless. :(

 

net use "UNC"\f$ /user:admin p@ssword

complete succes

 

I try to edit the "UNC"\f$ /user:admin p@ssword to (\\)"UNC"\f$ /user:admin p@ssword,, but edugeek does not correct it.?

 

But when I use this line, i get a error.

 

del /q /s "C:\users\CS Dedicated Server CLI.Lnk" >>"UNC"\f$: \%computername%.txt

 

"System error 86 has occurred.

 

 

The specified network password is not correct.

 

 

Logon failure: unknown user name or bad password.

Press any key to continue . . .

 

pause"

 

Then I but the password in the line.

But get the same error

 

del /q /s "C:\users\CS Dedicated Server CLI.Lnk" >>"UNC"\f$: /user:"UNC" admin P@ssword \%computername%.txt

 

"System error 86 has occurred.

 

 

The specified network password is not correct.

 

 

Logon failure: unknown user name or bad password.

Press any key to continue . . ."

 

Edited by denmyos
added \\
Posted

Ok, diagnostic time. Open up File Explorer and in the address bar type \\UNC\

 

Hopefully you should get a prompt for a username and password. Try typing in the username field UNC\Username and your password in the password field. What happens and can you see your shared folder?

Posted (edited)

yes, and i have have access to everything in the shared folder.

 

And i use the same username and password as in my batch.

Edited by denmyos
Posted (edited)

I've just attached a screenshot of me accessing a share from a command prompt.

The share I am accessing is hidden, so it has a $ at the end, but it sounds like yours is not hidden as you could see it in Explorer, so should not need that part.

 

Test0001.png

 

Note: Before anyone asks, yes I do remember that this is public. The account I used is a test account, and has nothing to do with our live environment. ;)

Edited by DJ-1701

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...