Windows 7 Development: Shell Library

Source: Internet
Author: User

3. Compile and test the results:

A. Empty command line variables.

B. Open a command line window and change the directory (CD) to the location of the SLUtil.exe file (... \debug\slutil.exe)

C. Open the Library shell folder next to the Command Line window and you will see the changes you have made using the Slutil tool.

D. Try the following slutil command at the command line:

I.slutil?

Ii. Slutil Create Newlibrary

Iii. Slutil AddFolder newlibrary C:\Users

iv. Slutil Removefolder newlibrary C:\Users

Attention:

Because the interpreter can find the most matching command, you can use the "Slutil Cr Lib" directive to create a library, or use the "Slutil add lib C:\" instruction to add a folder. Try it.

Task 4– Add delete and rename commands

Deleting and renaming a library is a series of actions to delete or rename a library of its consistent *.library-ms files. To delete a file, we can use SHFileOperation () or DeleteFile (). The first method can put the library into the Recycle Bin at the same time, and the subsequent operation is simpler, so we will use this method. If you want to rename the file, we can use the File-based API again, but we can also use the Copy library, and then delete the original instance.

1. Add the following code to the SLUtil.cpp file:

C + + (SLUtil.cpp)

//delete a library


void Delete (const CCommand &command, const vector<pcwstr> &arguments)


{


Pwstr Libraryfullpath;


HRESULT hr = Getlibraryfromlibrariesfolder (Arguments[0], NULL, false,


&libraryfullpath);





if (FAILED (HR))


                 {


wcerr << L "Delete:can ' t get library." << Endl;


exit (4);


                 }


//we use deletes file with the library File-system based full path


DeleteFile (Libraryfullpath);


CoTaskMemFree (Libraryfullpath);


}


COMMAND (l "Delete", l "slutil delete LibraryName", l "delete a library", l "slutil Delete Mylib", 1, delete);





//rename an existing library


void Rename (const CCommand &command, const vector<pcwstr> &arguments)


{


ishelllibrary *shelllibrary = openlibrary (L "Rename", Arguments[0]);


IShellItem *savedto = NULL;





//save A new copy of the library under the user ' s libraries folder with


//the new name.


HRESULT hr = shelllibrary->saveinknownfolder (folderid_userslibraries,


Arguments[1], lsf_makeuniquename , &savedto);


if (FAILED (HR))


                 {


wcerr << L "Rename:can ' t Save library." << Endl;


Exit (5);


                 }





if (shelllibrary!= NULL)


shelllibrary->release ();


if (savedto!= NULL)


savedto->release ();





//create parameters to delete the old copy of the library


vector<pcwstr> deletearguments;


deletearguments.push_back (arguments [0]);





//call the Delete command


Delete (command, deletearguments);


}


COMMAND (L "Rename", L "slutil Rename oldname NewName", l "Rename a Library", l ' slutil Rename mylib-Mylibnewname ', 2, R ENAME);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.