[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Logon scrript that can remove all the default shares except c$

Posted on 2007-10-19
Medium Priority
Last Modified: 2010-04-16

Logon scrript that can remove all the default shares except c$.

Is there a way on logon that we can disable.

Question by:bsharath
  • 2
  • 2
LVL 51

Expert Comment

ID: 20108138
This should work in a CMD file.

net share Admin$ /d
net share IPC$ /d


Expert Comment

ID: 20108142
Not disable - but delete all shares

reg delete HKLM\System\CurrentControlSet\Services\lanmanserver\Shares /f
net stop "computer browser"
net stop server
net start "computer browser"

kills all shares except admin shares

You may have an issue if the user does not have enough registry rights to delete this key, so you may need to be creative with group policy or use the runas command.
LVL 51

Expert Comment

ID: 20108143
I should add that this may be necessary to run from a GPO using a Computer Startup script.

LVL 11

Author Comment

ID: 20108897

Where should i put these commands I just wabt to remove the d$, e$, F$ excluding Ipc$,Admin$ and C$

Accepted Solution

mb042 earned 2000 total points
ID: 20113166
Go to scheduled tasks and create a task for each share you want to delete
(Wizard method:
Pick any program (next)
name it SHAREFIX1 (or something meaningfull with no spaces)
choose When my computer starts (next)
enter a user and password that has administrative rights on all workstations (next)
tick Open advanced...  (Finish)
Change the run line to: net share d$ /d (or whichever share)
if the start line has a path, clear it.
If you want to control share deletion using the logon script only, then untick Enabled. (OK)
Now copy and paste this task in to your netlogon directory
(repeat for each share you want to remove)
now add the following lines to your logon script
copy \\servername\netlogon\sharefix1.job %systemroot%\tasks
schtasks /Run /TN sharefix1
.....repeat for each sharefix


Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses
Course of the Month19 days, 2 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question