Petri.co.il forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > General Scripting
Petri.co.il is happy to award RicklesP the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read
Notices

Xcopy - Invalid number of parameters

Xcopy - Invalid number of parameters

this thread has 6 replies and has been viewed 30122 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 18th March 2009, 13:52
Deland01 Deland01 is offline
Member
Staying around
 
 Join Date: Jan 2007
  6 month star 12 month star
 Posts: 294
 Reputation: Deland01 will become famous soon enough (76)
Default Xcopy - Invalid number of parameters

Can anyone help with this one?

I’m trying to copy the Group Policy folders from my USB memory stick to a laptop. This will update the GPO with a batch file rather than manually copying the folders over.


I have the USB drive mapped as the Z: drive on the laptop.
The GPO folders I need to copy are on the USB drive in the following location:

Z:\Advisor GPO\GPO Enabled\Machine
Z:\Advisor GPO\GPO Enabled\User

I need to copy both folders to:

%SystemRoot%\system32\GroupPolicy

My scrip is as follows:

xcopy Z:\Advisor GPO\GPO Enabled\Machine\* %SYSTEMROOT%\system32\GroupPolicy /e /v /c /i /h /r /y
xcopy Z:\Advisor GPO\GPO Enabled\User\* %SYSTEMROOT%\system32\GroupPolicy /e /v /c /i /h /r /y
gpupdate /force


When I run the script I see "Invalid Number of parameters". So I tried running this instead:

xcopy Z:\Advisor GPO\GPO Enabled\Machine\* %SYSTEMROOT%\system32\GroupPolicy

I still see the same error, what am I doing wrong??


.
  #2  
Old 18th March 2009, 14:57
Rems's Avatar
Rems Rems is offline
Moderator
 
 Join Date: Mar 2005
  6 month star 12 month star
 Location: NL
 Posts: 2,431
 Reputation: Rems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to behold (965)
Default Re: Xcopy - Invalid number of parameters

The source paths contain spaces therefore you have to use quote-signs around the path.
The path Z:\Advisor GPO\GPO Enabled\Machine\* should be written like "Z:\Advisor GPO\GPO Enabled\Machine\*"
(or, when the batch file is on Z: use the path of the batchfile (%~dp0) exented with the subfolders you like to copy: "%~dp0Advisor GPO\GPO Enabled\Machine\*" )

Is OK if you put all paths between quotes also: "%SYSTEMROOT%\system32\GroupPolicy\"


\Rems
__________________

This posting is provided "AS IS" with no warranties, and confers no rights.

__________________

** Remember to give credit where credit's due **
and leave Reputation Points for meaningful posts
  #3  
Old 18th March 2009, 15:11
Deland01 Deland01 is offline
Member
Staying around
 
 Join Date: Jan 2007
  6 month star 12 month star
 Posts: 294
 Reputation: Deland01 will become famous soon enough (76)
Default Re: Xcopy - Invalid number of parameters

As simple as that then, just needed the quotations.

The script works a treat but it doesnt seam to be updating the GPO now, any ideas why?

I can still do this manually & it works


Also not sure what you mean by (%~dp0)
  #4  
Old 18th March 2009, 17:19
Deland01 Deland01 is offline
Member
Staying around
 
 Join Date: Jan 2007
  6 month star 12 month star
 Posts: 294
 Reputation: Deland01 will become famous soon enough (76)
Default Re: Xcopy - Invalid number of parameters

Had a few problems getting this to work but a bit of perseverance won out in this case. Here what the wining scripts were:

GPO Enable
xcopy "Z:\AdvisorGPO\GPOEnabled\Machine\*" %SYSTEMROOT%\system32\GroupPolicy\Machine /e /v /c /i /h /r /y
xcopy "Z:\AdvisorGPO\GPOEnabled\User\*" %SYSTEMROOT%\system32\GroupPolicy\User /e /v /c /i /h /r /y
gpupdate /force


GPO Disable
xcopy "Z:\AdvisorGPO\GPODisabled\Machine\*" %SYSTEMROOT%\system32\GroupPolicy\Machine /e /v /c /i /h /r /y
xcopy "Z:\AdvisorGPO\GPODisabled\User\*" %SYSTEMROOT%\system32\GroupPolicy\User /e /v /c /i /h /r /y
gpupdate /force


Thanks again for the help


.
  #5  
Old 18th March 2009, 18:27
cruachan's Avatar
MVM cruachan cruachan is offline
Senior Member
MVM
 
 Join Date: Jun 2008
  6 month star 12 month star
 Location: Hamilton, Scotland
 Posts: 2,076
 Reputation: cruachan is just really nicecruachan is just really nicecruachan is just really nicecruachan is just really nice (381)
Default Re: Xcopy - Invalid number of parameters

FWIW I've recently updated all of our scripts that used to use xcopy to use robocopy, which is much easier to configure, much more robust and has a lot more options. It's native in Vista/Server 2008 and part of the 2K3 resource kit. Well worth a look.
  #6  
Old 19th March 2009, 00:58
Rems's Avatar
Rems Rems is offline
Moderator
 
 Join Date: Mar 2005
  6 month star 12 month star
 Location: NL
 Posts: 2,431
 Reputation: Rems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to behold (965)
Default Re: Xcopy - Invalid number of parameters

Glad you got it sorted.


\Rems



Quote:
Originally Posted by Deland01 View Post
not sure what you mean by (%~dp0)
The variable %0 is by default the program name as it was called. It can expand in the batch the path from were the batch is executed including the batchfile name (http://www.robvanderwoude.com/parameters.php). Furthermore, you can use variable modifiers on %0 to expand only the drive letter or path to the batchfile.

When you use the %0 with the modifiers ~dp it is entered like: %~dp0 Using this in your batch it will echo the location of the batch.
So if the batch is on the same usb-device as the folders and files you want to copy, you can use the location of the batch (or just expand the drive letter when you use: %~d0 ) as a starting point for the location of the source folders that you want to copy to the computer for the XCOPY command.
This way you do not need to worry about the usb-drive is explicitly assigned the drive letter Z: on every computer on were you run this batch.

The following samples batch can show you what I mean,
Code:
@echo off
Set "percentsignZero=%%0" (this variable is just used for descriptions echoed before each sample in this batch)


echo The variable %percentsignZero% is the program name as it was called.
echo It will expand the path including the batchfile name.

echo/&rem -=sample=-
echo.  Expanding the variable %percentsignZero%
echo.  %0

echo/
echo/
:: http://www.robvanderwoude.com/parameters.php
echo Substitution of Batch-Parameter and FOR variable references has been enhanced.
echo You can use the following variable modifiers when is it for existing files.
echo The available modifiers are:

echo/&rem -=sample=-
echo. 1.The modifier ~ expand %percentsignZero% but it removes any surrounding quotes
echo.   %~0

echo/&rem -=sample=-
echo. 2.The modifier ~f can expand %percentsignZero% to a fully qualified path name
echo.   %~f0

echo/&rem -=sample=-
echo. 3.The modifier ~p can expand %percentsignZero% to a path only (without the driveletter)
echo.   %~p0

echo/&rem -=sample=-
echo. 4.The modifier ~d can expand %percentsignZero% to a drive letter only
echo.   %~d0

echo/&rem -=sample=-
echo. 5.The modifier ~n can expand %percentsignZero% to a file name only (without the extension)
echo.   %~n0

echo/&rem -=sample=-
echo. 6.The modifier ~x can expand %percentsignZero% to a file extension only
echo.   %~x0

echo/&rem -=sample=-
echo. 7.The modifier ~s can expand %percentsignZero% to a path contains short names
echo.   %~s0

echo/&rem -=sample=-
echo. 8.Extra modifiers ~a ~t and ~z can expand resectively,
echo.   the file attributes  : %~a0 bits
echo.   datetime lastmodified: %~t0
echo.   size of file         : %~z0  bytes

echo/
echo/
echo The modifiers can be combined (in the desired order) to get compound results:

echo/&rem -=sample=-
echo. * The modifiers ~dp expands the drive letter and path
echo.   %~dp0

echo/&rem -=sample=-
echo. * The modifiers ~nx expands file name and extension
echo.   %~nx0

echo/&rem -=sample=-
echo. * The combined modifiers ~fs expands the full path name with short names
echo.   %~fs0

echo/
echo/
:: Alternative of using the modifier combination ~dp
:: see http://support.microsoft.com/kb/121387 (i.e. Dir/p %0\..\"subfolder\filename" )
pause
__________________

This posting is provided "AS IS" with no warranties, and confers no rights.

__________________

** Remember to give credit where credit's due **
and leave Reputation Points for meaningful posts
  #7  
Old 19th March 2009, 20:12
Deland01 Deland01 is offline
Member
Staying around
 
 Join Date: Jan 2007
  6 month star 12 month star
 Posts: 294
 Reputation: Deland01 will become famous soon enough (76)
Default Re: Xcopy - Invalid number of parameters

Rems - I looked all over the net for a way how to do this but wasn’t really sure what to look for. Imp not a programmer and this looks like it might take me a while to figure out but I'll defiantly have a bash.

cruachan - would this work on XP Pro without having to install the resource pack first?
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with script or xcopy command Lamberth General Scripting 4 1st September 2008 18:12
help with Xcopy - File name or Directory Retaliator General Scripting 2 24th October 2007 13:07
Problem with Xcopy in Startup script ccook13 DOS Command Shell 5 8th January 2007 18:41
Need Help With Batch file xCopy djturizmo General Scripting 7 17th January 2006 12:40
xcopy command for NTFS partitions david-uk Windows Server 2000 / 2003 / 2003 R2 3 5th May 2004 10:58


All times are GMT +3. The time now is 23:41.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri