Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.3 KiB

  1. package OpShellFolder;
  2. $ENV{script_name} = 'OpShellFolder.pl';
  3. use Win32API::Registry 0.13 qw( :ALL );
  4. my %OpSyntax = (
  5. remark => [0,"rem"],
  6. copyfileto => [6,"copy"],
  7. copyfilefrom => [5,"copy"],
  8. copyfolderto => [6,"copy"],
  9. copyfolderfrom => [3,"copy"],
  10. delfolder => [1,"del /s /q"],
  11. delfile => [2,"del"],
  12. renamefolderto => [4,"ren"],
  13. renamefolderfrom => [3,"ren"],
  14. renamefileto => [6,"ren"],
  15. renamefilefrom => [5,"ren"],
  16. movefolderto => [4,"move"],
  17. movefolderfrom => [3,"move"],
  18. movefileto => [6,"move"],
  19. movefilefrom => [5,"move"]
  20. );
  21. my %ShellFolderKeys = map({$_ => 1}
  22. (qw(AppData Cache Cookies Desktop Favorites
  23. History Personal Programs Startup Templates),
  24. "My Pictures", "Start Menu")
  25. );
  26. sub OpShellFolder {
  27. my ($op, $shellfolderkey, $something) = @_;
  28. my ($type, $shellfolder, $opcmd, @Syntax, $key, $wkey);
  29. $op = lc$op;
  30. if (!exists $OpSyntax{$op}) {
  31. print "Error - $op is not an invalid operation\n";
  32. return;
  33. }
  34. if (!exists $ShellFolderKeys{$shellfolderkey}) {
  35. print "Error - $shellfolderkey is not an invalid shell folder key\n";
  36. return;
  37. }
  38. $something=~/([^\\]+)$/;
  39. ($something_filepath, $something_filename)=($`, $1);
  40. # Retrive the registry keys
  41. RegOpenKeyEx( HKEY_CURRENT_USER,
  42. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", 0, KEY_READ, $wkey )
  43. or die "Can't open HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders: $^E\n";
  44. RegQueryValueEx( $wkey, $shellfolderkey, [], $type, $shellfolder, [] )
  45. or die "Can't read HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders: $^E\n";
  46. RegCloseKey( $wkey );
  47. $opcmd = $OpSyntax{$op}[1];
  48. @Syntax = (
  49. "$opcmd $something", #0
  50. "$opcmd \"$shellfolder\"", #1
  51. "$opcmd \"$shellfolder\"\\\"$something\"", #2
  52. "$opcmd \"$shellfolder\" \"$something\"", #3
  53. "$opcmd \"$something\" \"$shellfolder\"", #4
  54. "$opcmd \"$shellfolder\"\\\"$something_filename\" \"$something\"", #5
  55. "$opcmd \"$something\" \"$shellfolder\"\\\"$something_filename\"", #6
  56. );
  57. system($Syntax[$OpSyntax{$op}[0]]);
  58. }
  59. # Cmd entry point for script.
  60. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pl\$/i")) {
  61. &OpShellFolder(@ARGV);
  62. }
  63. 1;