I'm trying to rename a folder on logoff, but I keep getting an error in my
code. So far my code is:

Option Explicit ' Force explicit declarations
'
' Variables
'
Dim WSHNetwork
Dim objWMIService
Dim defFolders
Dim colFolders
Dim wshShell
Dim strComputer

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WSHNetwork = WScript.CreateObject("WScript.Network")

strComputer = ""
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set defFolders = objWMIService.ExecQuery _
("SELECT * FROM Win32_Directory WHERE Name = 'c:\\Domuntes and
Settings\Default User'")
For Each objFolder in defFolders
errResults = objFolder.Rename("C:\Documents and Settings\Default Old")
WScript.Echo errResults
Next
Set colFolders = objWMIService.ExecQuery _
("SELECT * FROM Win32_Directory WHERE Name = 'c:\\Documents and
Settings\%UserName%'")
For Each objFolder in colFolders
errResults = objFolder.Rename("C:\Documents and Settings\Default User")
Wscript.Echo errResults
Next

I'm getting an error on line 16, Please help.

Re: Rename folders? by Rob

Rob
Wed Jul 16 10:35:35 CDT 2003

Looks like it's the strComputer variable -- should be:
strComputer = "."

This variable is used in connecting to the machine with GetObject in the
next line. The "." means the local PC.

Rob

> strComputer = ""
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")



Re: Rename folders? by Rob

Rob
Wed Jul 16 11:44:32 CDT 2003

Try this.. Stick the new name into a variable...

strNewName = "C:\Documents and Settings\Default User"

Then use it.

objFolder.Rename(strNewName)

That's just off the top of my head.

Rob


> errResults = objFolder.Rename("C:\documents and settings\default old")
>
> The problem is the "documents and settings" part of the script. It
doesn't
> seem to like the spaces in the folder name. I alievated part of the
problem
> by using %userprofile%, but I need to rename that folder to 'default
user'.
> Any suggestions.
> "Rob Wiltbank" <wynder@warcry.com> wrote in message
> news:OLmRq$6SDHA.3796@tk2msftngp13.phx.gbl...
> > Looks like it's the strComputer variable -- should be:
> > strComputer = "."
> >
> > This variable is used in connecting to the machine with GetObject in the
> > next line. The "." means the local PC.
> >
> > Rob
> >
> > > strComputer = ""
> > > Set objWMIService = GetObject("winmgmts:" _
> > > & "{impersonationLevel=impersonate}!\\" & strComputer &
> "\root\cimv2")
> >
> >
>
>



Re: Rename folders? by Nathan

Nathan
Wed Jul 16 14:30:09 CDT 2003

Valiant effort, but it didn't work. I need to find a way to rename a user's
profile to default user. That way when they log on again with a new naming
convention, they'll get their profile.
"Rob Wiltbank" <wynder@warcry.com> wrote in message
news:#BggJm7SDHA.1576@TK2MSFTNGP12.phx.gbl...
> Try this.. Stick the new name into a variable...
>
> strNewName = "C:\Documents and Settings\Default User"
>
> Then use it.
>
> objFolder.Rename(strNewName)
>
> That's just off the top of my head.
>
> Rob
>
>
> > errResults = objFolder.Rename("C:\documents and settings\default
old")
> >
> > The problem is the "documents and settings" part of the script. It
> doesn't
> > seem to like the spaces in the folder name. I alievated part of the
> problem
> > by using %userprofile%, but I need to rename that folder to 'default
> user'.
> > Any suggestions.
> > "Rob Wiltbank" <wynder@warcry.com> wrote in message
> > news:OLmRq$6SDHA.3796@tk2msftngp13.phx.gbl...
> > > Looks like it's the strComputer variable -- should be:
> > > strComputer = "."
> > >
> > > This variable is used in connecting to the machine with GetObject in
the
> > > next line. The "." means the local PC.
> > >
> > > Rob
> > >
> > > > strComputer = ""
> > > > Set objWMIService = GetObject("winmgmts:" _
> > > > & "{impersonationLevel=impersonate}!\\" & strComputer &
> > "\root\cimv2")
> > >
> > >
> >
> >
>
>



Re: Rename folders? by Greg

Greg
Mon Sep 29 10:01:06 CDT 2003

Nathan, did you ever get this working? I'm trying to do something
similar and would appreciate knowing how you got this working.

Thanks




Nathan Guidry wrote:
> Valiant effort, but it didn't work. I need to find a way to rename a user's
> profile to default user. That way when they log on again with a new naming
> convention, they'll get their profile.
> "Rob Wiltbank" <wynder@warcry.com> wrote in message
> news:#BggJm7SDHA.1576@TK2MSFTNGP12.phx.gbl...
>
>>Try this.. Stick the new name into a variable...
>>
>>strNewName = "C:\Documents and Settings\Default User"
>>
>>Then use it.
>>
>>objFolder.Rename(strNewName)
>>
>>That's just off the top of my head.
>>
>>Rob
>>
>>
>>
>>> errResults = objFolder.Rename("C:\documents and settings\default
>
> old")
>
>>>The problem is the "documents and settings" part of the script. It
>>
>>doesn't
>>
>>>seem to like the spaces in the folder name. I alievated part of the
>>
>>problem
>>
>>>by using %userprofile%, but I need to rename that folder to 'default
>>
>>user'.
>>
>>>Any suggestions.
>>>"Rob Wiltbank" <wynder@warcry.com> wrote in message
>>>news:OLmRq$6SDHA.3796@tk2msftngp13.phx.gbl...
>>>
>>>>Looks like it's the strComputer variable -- should be:
>>>>strComputer = "."
>>>>
>>>>This variable is used in connecting to the machine with GetObject in
>
> the
>
>>>>next line. The "." means the local PC.
>>>>
>>>>Rob
>>>>
>>>>
>>>>>strComputer = ""
>>>>>Set objWMIService = GetObject("winmgmts:" _
>>>>> & "{impersonationLevel=impersonate}!\\" & strComputer &
>>>
>>>"\root\cimv2")
>>>
>>>>
>>>
>>
>
>


Re: Rename folders? by TDM

TDM
Tue Sep 30 12:26:31 CDT 2003


The method I chose was to "copy" the profile to "Default User", that way
you still have the old profile around if there are problems. This will only
work if the user is not logged in, which is of course true for the
move/rename
as well. I thought it also wise to make a make a backup copy of the standard
"Default User" profile before the copy, then put it back after the user
logged
in. Otherwise, all users logging in to that macine will get "that users"
profile
which is perhaps OK in some situations. If you have admin rights to the
machine
you can do all this remotely as well.

My $.02 worth.

TDM

"Greg S. Blackman" <groggrog@comcast.net> wrote in message
news:3F784931.2030907@comcast.net...
> Nathan, did you ever get this working? I'm trying to do something
> similar and would appreciate knowing how you got this working.
>
> Thanks
>
>
>
>
> Nathan Guidry wrote:
> > Valiant effort, but it didn't work. I need to find a way to rename a
user's
> > profile to default user. That way when they log on again with a new
naming
> > convention, they'll get their profile.
> > "Rob Wiltbank" <wynder@warcry.com> wrote in message
> > news:#BggJm7SDHA.1576@TK2MSFTNGP12.phx.gbl...
> >
> >>Try this.. Stick the new name into a variable...
> >>
> >>strNewName = "C:\Documents and Settings\Default User"
> >>
> >>Then use it.
> >>
> >>objFolder.Rename(strNewName)
> >>
> >>That's just off the top of my head.
> >>
> >>Rob
> >>
> >>
> >>
> >>> errResults = objFolder.Rename("C:\documents and settings\default
> >
> > old")
> >
> >>>The problem is the "documents and settings" part of the script. It
> >>
> >>doesn't
> >>
> >>>seem to like the spaces in the folder name. I alievated part of the
> >>
> >>problem
> >>
> >>>by using %userprofile%, but I need to rename that folder to 'default
> >>
> >>user'.
> >>
> >>>Any suggestions.
> >>>"Rob Wiltbank" <wynder@warcry.com> wrote in message
> >>>news:OLmRq$6SDHA.3796@tk2msftngp13.phx.gbl...
> >>>
> >>>>Looks like it's the strComputer variable -- should be:
> >>>>strComputer = "."
> >>>>
> >>>>This variable is used in connecting to the machine with GetObject in
> >
> > the
> >
> >>>>next line. The "." means the local PC.
> >>>>
> >>>>Rob
> >>>>
> >>>>
> >>>>>strComputer = ""
> >>>>>Set objWMIService = GetObject("winmgmts:" _
> >>>>> & "{impersonationLevel=impersonate}!\\" & strComputer &
> >>>
> >>>"\root\cimv2")
> >>>
> >>>>
> >>>
> >>
> >
> >
>