Solved

running csccmd at logon script

Posted on 2008-10-15
9
790 Views
Last Modified: 2012-05-05
Dear Expert.

I have created a VB script thar will start when domain user logon. The script will move the offline folder cache from oldserver to new server.
Set objShell = CreateObject(WScript.Shell)
objShell.Run "csccmd /moveshare:\\olderserver\%username%$\docs \\newserver\%username%$\docs"

Where %username% is a variable.The problem is I have noticed that the script never run; Could guide me where I am wrong

thsk in advance
0
Comment
Question by:madinina
  • 4
  • 3
  • 2
9 Comments
 
LVL 7

Expert Comment

by:Hubasan
Comment Utility
Hi madinina,

%username% environmental variable needs to be extracted within the script first in order for that to work. I would suggest the following code.

First, put this on top of your script

Set oNet = CreateObject("wscript.network")
sUser = oNet.UserName

and then use the code below instead your code:
Set objShell = CreateObject(WScript.Shell)

objShell.Run "csccmd /moveshare:\\olderserver\" & sUser & "$\docs \\newserver\" & sUser & "$\docs"

Open in new window

0
 
LVL 7

Expert Comment

by:Hubasan
Comment Utility
Oh and one more thing i just noticed your code for the object needs double quotes in the brackets like this:
Set objShell = CreateObject("WScript.Shell")

So your code would be like below:

Set objShell = CreateObject("WScript.Shell")

objShell.Run "csccmd /moveshare:\\olderserver\" & sUser & "$\docs \\newserver\" & sUser & "$\docs"

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
Hi, in VBScript, you need to expand the %USERPROFILE% environment variable to be able to use it.

Regards,

Rob.
Set objShell = CreateObject("WScript.Shell")

sUser = objShell.ExpandEnvironmentStrings("%USERNAME%")

objShell.Run "csccmd /moveshare:\\olderserver\" & sUser & "$\docs \\newserver\" & sUser & "$\docs"

Open in new window

0
 

Author Comment

by:madinina
Comment Utility
Thks to All. Will have a try and let you know
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:madinina
Comment Utility
Dear All,

I have created two scripts :

1 - One for computer GPO that run at startup:
            regedit.exe  CleanCSC.reg /f. where CleanCSC contains these lines

                 Windows Registry Editor Version 5.00
                      [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\NetCache]
                      "FormatDatabase"=dword:00000001

2 - One for User GPO that run at logon:

set objShell = CreateObject("WScript.Shell")
sUser = objShell.ExpandEnvironmentStrings("%USERNAME%")

            strRegKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal"
            strRedirectionPath = "\\mosv03.mo.conair.com\%USERNAME%$\Data"
            strRedirectRegType = "REG_EXPAND_SZ"

' Write the new Personal path
objShell.RegWrite strRegKey, strRedirectionPath, strRedirectRegType


objShell.Run "csccmd /moveshare:\\oldserver\" & sUser & "$\Data \\newserver\" & sUser & "$\Data"

' Variable Destruction
Set objShell = Nothing

I have one doubt. That Computer GPO (clean CSC cache) ran before user GPO (move CSC from old server to new server)

Any suggestions will be appreciated.

Thks in advance
0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
>> That Computer GPO (clean CSC cache) ran before user GPO (move CSC from old server to new server)

That is the way it is designed to run.  Computer Scripts run before anyone logs in.

Will this actually create a problem though?  Does setting FormatDatabase to any value actually delete all cached files?

Regards,

Rob.
0
 

Author Comment

by:madinina
Comment Utility
Hi RobSampson,

Yeah... it will . Because running clean CSC cache before moving CSC cache will delete all cached files.

Madinina
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
Comment Utility
OK, so what if you made the StartUp script a ShutDown script instead?  Would that work?

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
Thanks for the grade.

Regards,

Rob.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now