Adding files for installer - c#

I can Add .JPEG, .PNG, .SDF, .MDF and etc.. but why I can't add .Ink extension for my Setup Project?

.Ink is shortcut i think that's why you can't add it , i think you want to create a shortcut in the desktop for that you can try this
Imports IWshRuntimeLibrary
Dim WshShell As WshShellClass = New WshShellClass
Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut
' The shortcut will be created on the desktop
Dim DesktopFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
MyShortcut = CType(WshShell.CreateShortcut(DesktopFolder & "\MyShortcutName.lnk"), IWshRuntimeLibrary.IWshShortcut)
MyShortcut.TargetPath = Application.StartupPath & "\YourApp.exe" 'Specify target app full path
MyShortcut.Save()
End Sub

Related

Programmatically create a shortcut to the recycle bin or other special folders

I'm trying to make a console app that will create shortcut of Recycle bin.
My code:
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
object shDesktop = (object)"Desktop";
WshShell shell = new WshShell();
string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + #"\Recycle Bin.lnk";
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.Description = "New shortcut for Recycle Bin";
shortcut.Hotkey = "Ctrl+Shift+N";
shortcut.IconLocation = #"C:\WINDOWS\System32\imageres.dll";
shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + #"\Recycle.Bin";
shortcut.Save();
It Creates a "Shortcut" but it's not usable at all. A message pops up when. I try to open it which produces:
"Windows is searching for recycle.bin. To locate your file yourself click browse."
Specify the special CLSID of the Recycle Bin as TargetPath:
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.TargetPath = "::{645ff040-5081-101b-9f08-00aa002f954e}";
shortcut.Save();
There's also no need to specify IconLocation. The appropriate Icon is chosen automatically in the case of special folders.
If you want to create a shortcut that opens special folders, you need to create a shortcut to explorer.exe and pass the appropriate GUID prefixed with a double colon as argument:
string explorerExePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe");
shortcut.TargetPath = explorerExePath;
shortcut.Arguments = "::{645FF040-5081-101B-9F08-00AA002F954E}";
You don't even need to provide the explorer.exe as target, you can target the GUID directly:
shortcut.TargetPath = "::{645FF040-5081-101B-9F08-00AA002F954E}";
Alternatively, you can just enable the display of the Recycle Bin on the desktop instead.

How to encrypt files using EFS with vbscript?

Is it possible to programmatically encrypt files (with EFS) using vbscript. Are there any EFS API's that can be used with c# on windows 7?
I translated your answer to C#:
WshShell sh1 = new WshShell();
var retval = sh1.Run("CIPHER /E /S:" & strDir, 0, True);
No answers yet !! meanwhile one option was to use the folowing script
Dim strDir, objShell, FSO, WshShell
strDir = "D:\TestFolder"
Set objShell = CreateObject("Shell.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
retval = WshShell.Run("CIPHER /E /S:" & strDir, 0, True)
MsgBox("Success")

How to create GPO programmatically?

I need to deploy my vb.net application via group policy. I found some information on how to do this here http://windowsdevcenter.com/pub/a/windows/2006/11/14/how-to-deploy-software-using-group-policy.html.
Now I need to do the same programmatically.
Please suggest some link, document or tutorial on this.
Well,
I don't think there is documented API to create GPO. You may create it manually and then use CreateGPOLink function to link it to OU's
Just found PS script that suppose to create new GPO's, thought it may be help for you http://blogs.technet.com/b/heyscriptingguy/archive/2009/02/11/how-can-i-create-new-group-policy-objects.aspx
I think your question is answered here C# linking group policy in AD
Hope this helps. Like I said, it's ugly but it works. You'll probably have to install the Group Policy Management Console so you can add a reference to GPMGMTLib.dll. This is directly from my code so you'll have to play with it but it should get you going in the right direction:
Dim GPM As New GPMGMTLib.GPM
Dim GPMConst As GPMGMTLib.GPMConstants = GPM.GetConstants
Dim GPMDomain As GPMGMTLib.GPMDomain = GPM.GetDomain(Environment.GetEnvironmentVariable("USERDNSDOMAIN"), "", GPMConst.UseAnyDC)
Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
'Dim GPMSOM As GPMGMTLib.GPMSOM = GPMDomain.GetSOM("OU name") 'to link to specific OU
Dim GPMSOM As GPMGMTLib.GPMSOM = GPMDomain.GetSOM(RootDSE.Properties("defaultNamingContext").Value.ToString()) '//DC=domain,DC=test
'//=======================
'//see if we already exist
'//=======================
Dim GPMSearchExisting As GPMGMTLib.GPMSearchCriteria = GPM.CreateSearchCriteria
GPMSearchExisting.Add(GPMConst.SearchPropertyGPODisplayName, GPMGMTLib.GPMSearchOperation.opEquals, "Agent_Installation")
Dim GPOListExisting As GPMGMTLib.GPMGPOCollection = GPMDomain.SearchGPOs(GPMSearchExisting)
If GPOListExisting.Count <> 0 Then
MsgBox("GPO already exists.")
Exit Sub
End If
'//=============================================================================
'//copy compressed GPO template from embedded resources to filesystem then unzip
'//=============================================================================
lblStatus.Text += "Copying embedded GPO template to filesystem..." & vbNewLine
lblStatus.Refresh()
My.Computer.FileSystem.WriteAllBytes("c:\Agent_Installation_GPO.zip", My.Resources.Agent_Installation_GPO, False)
lblStatus.Text += "Extracting GPO template from archive..." & vbNewLine
lblStatus.Refresh()
Call UnZip("c:\Agent_Installation_GPO.zip", "c:\")
'//=========================================================================================
'//need to create a GPO migration table on the fly. see Create_Migration_Table() for details
'//=========================================================================================
lblStatus.Text += "Creating GPO migration table..." & vbNewLine
lblStatus.Refresh()
Call Create_Migration_Table("c:\Agent_Installation_GPO.migtable")
lblStatus.Text += "Creating GPO..." & vbNewLine
lblStatus.Refresh()
Dim GPO As GPMGMTLib.GPMGPO = GPMDomain.CreateGPO
GPO.DisplayName = "Agent_Installation"
lblStatus.Text += "Linking GPO to domain..." & vbNewLine
lblStatus.Refresh()
'//===========================
'//links the GPO to the domain
'//===========================
GPMSOM.CreateGPOLink(-1, GPO)
Dim GPMSearchCriteria As GPMGMTLib.GPMSearchCriteria = GPM.CreateSearchCriteria
GPMSearchCriteria.Add(GPMConst.SearchPropertyGPODisplayName, GPMGMTLib.GPMSearchOperation.opEquals, "Agent_Installation")
Dim GPOList As GPMGMTLib.GPMGPOCollection = GPMDomain.SearchGPOs(GPMSearchCriteria)
Dim GPMGPO As GPMGMTLib.GPMGPO = GPOList.Item(1)
lblStatus.Text += "Importing settings from template..." & vbNewLine
lblStatus.Refresh()
'//========================================================
'//link migration table to template and import all settings
'//========================================================
Dim GPMBackupDir As GPMGMTLib.GPMBackupDir = GPM.GetBackupDir("C:\Agent_Installation_GPO")
Dim GPMBackup As GPMGMTLib.GPMBackup = GPMBackupDir.GetBackup("{193E0BEE-B37E-4472-A032-F297C4A5D8E1}")
Dim GPMMigrationTable As GPMGMTLib.GPMMigrationTable = GPM.GetMigrationTable("c:\Agent_Installation_GPO.migtable")
Dim GPMResult As GPMGMTLib.GPMResult = GPMGPO.Import(0, GPMBackup, GPMMigrationTable)
lblStatus.Text += "Done"
lblStatus.Refresh()
And this this is the function that creates the migration table. For my test I used test.domain but as you can see I replace this with the current domain before I merge the XML. Note that the XML must be utf-16 or this won't work.
Using objWriter As New System.IO.StreamWriter(strPath, False, System.Text.Encoding.Unicode) '//must be utf-16
objWriter.WriteLine("<?xml version=""1.0"" encoding=""utf-16""?>")
objWriter.WriteLine("<MigrationTable xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://www.microsoft.com/GroupPolicy/GPOOperations/MigrationTable"">")
objWriter.WriteLine(" <Mapping>")
objWriter.WriteLine(" <Type>UNCPath</Type>")
objWriter.WriteLine(" <Source>\\test.domain\netlogon</Source>")
objWriter.WriteLine(" <Destination>\\" & Environment.GetEnvironmentVariable("USERDNSDOMAIN") & "\netlogon</Destination>")
objWriter.WriteLine(" </Mapping>")
objWriter.Write("</MigrationTable>")
objWriter.Close()
End Using

How can I create a 'power options' shortcut on desktop with C# code?

How can I create a shortcut of power options with C# code?
This is my code:
WshShellClass wshShell = new WshShellClass();
IWshRuntimeLibrary.IWshShortcut MyShortcut;
MyShortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(#"C:\user\Administrator\power options.lnk");
MyShortcut.TargetPath = ???????;
MyShortcut.IconLocation = Application.StartupPath + ??????;
MyShortcut.Save();
Building on the answer from Moo-Juice, try the following:
WshShell shell = new WshShell();
string app = Path.Combine(Environment.SystemDirectory, "powercfg.cpl");
string linkPath = #"C:\PowerLink.lnk";
IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(linkPath);
link.TargetPath = app;
link.IconLocation = string.Format("{0},2", app);
link.Save();
The items in the control panel are stored in C:\windows\system32 with a .cpl extension. Therefore your target, for power options, should be:
C:\windows\system32\powercfg.cpl
Note: Do not use the hard-coded strings I have used here, use Environment.SystemDirectory to locate the directory appropriately.

How to set a custom Icon of an Outlook folder?

Is there any way to set a custom Icon of an Outlook folder or subfolder using Outlook object model?
As from Outlook 2010 you can use MAPIFolder.SetCUstomIcon as described above.
I have had the same challenge recently and found a nice snippet of VBA code at
Change Outlook folders colors possible?:
joelandre Jan 12, 2015 at 9:13 PM
Unzip the file icons.zip to C:\icons
Define the code below as Visual Basic Macros
Adapt the function ColorizeOutlookFolders according to your needs Text
Function GetFolder(ByVal FolderPath As String) As Outlook.folder
' Returns an Outlook folder object basing on the folder path
'
Dim TempFolder As Outlook.folder
Dim FoldersArray As Variant
Dim i As Integer
On Error GoTo GetFolder_Error
'Remove Leading slashes in the folder path
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set TempFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not TempFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = TempFolder.Folders
Set TempFolder = SubFolders.Item(FoldersArray(i))
If TempFolder Is Nothing Then
Set GetFolder = Nothing
End If
Next
End If
'Return the TempFolder
Set GetFolder = TempFolder
Exit Function GetFolder_Error:
Set GetFolder = Nothing
Exit Function End Function Sub ColorizeOneFolder(FolderPath As String, FolderColour As String)
Dim myPic As IPictureDisp
Dim folder As Outlook.folder
Set folder = GetFolder(FolderPath)
Set myPic = LoadPicture("C:\icons\" + FolderColour + ".ico")
If Not (folder Is Nothing) Then
' set a custom icon to the folder
folder.SetCustomIcon myPic
'Debug.Print "setting colour to " + FolderPath + " as " + FolderColour
End If End Sub
Sub ColorizeFolderAndSubFolders(strFolderPath As String, strFolderColour As String)
' this procedure colorizes the foler given by strFolderPath and all subfolfers
Dim olProjectRootFolder As Outlook.folder
Set olProjectRootFolder = GetFolder(strFolderPath)
Dim i As Long
Dim olNewFolder As Outlook.MAPIFolder
Dim olTempFolder As Outlook.MAPIFolder
Dim strTempFolderPath As String
' colorize folder
Call ColorizeOneFolder(strFolderPath, strFolderColour)
' Loop through the items in the current folder.
For i = olProjectRootFolder.Folders.Count To 1 Step -1
Set olTempFolder = olProjectRootFolder.Folders(i)
strTempFolderPath = olTempFolder.FolderPath
'prints the folder path and name in the VB Editor's Immediate window
'Debug.Print sTempFolderPath
' colorize folder
Call ColorizeOneFolder(strTempFolderPath, strFolderColour)
Next
For Each olNewFolder In olProjectRootFolder.Folders
' recursive call
'Debug.Print olNewFolder.FolderPath
Call ColorizeFolderAndSubFolders(olNewFolder.FolderPath, strFolderColour)
Next
End Sub
Sub ColorizeOutlookFolders()
Call ColorizeFolderAndSubFolders("\\Personal\Documents\000-Mgmt-CH\100-People", "blue")
Call ColorizeFolderAndSubFolders("\\Personal\Documents\000-Mgmt-CH\200-Projects","red")
Call ColorizeFolderAndSubFolders("\\Personal\Documents\000-Mgmt-CH\500-Meeting", "green")
Call ColorizeFolderAndSubFolders("\\Personal\Documents\000-Mgmt-CH\800-Product", "magenta")
Call ColorizeFolderAndSubFolders("\\Personal\Documents\000-Mgmt-CH\600-Departments", "grey")
Call ColorizeFolderAndSubFolders("\\Mailbox - Dan Wilson\Inbox\Customers", "grey")
End Sub
In the object ThisOutlookSession, define the following function:
Private Sub Application_Startup()
ColorizeOutlookFolders
End Sub
and
In order to NOT color sub-folders, you can use the function
ColorizeOneFolder instead of ColorizeFolderAndSubFolders e.g.
Sub ColorizeOutlookFolders()
Call ColorizeOneFolder ("\\Personal\Documents\000-Mgmt-CH\100-People", "blue")
Call ColorizeOneFolder ("\\Personal\Documents\000-Mgmt-CH\200-Projects", "red")
Call ColorizeOneFolder ("\\Personal\Documents\000-Mgmt-CH\500-Meeting", "green")
Call ColorizeOneFolder ("\\Personal\Documents\000-Mgmt-CH\800-Product", "magenta")
Call ColorizeOneFolder ("\\Personal\Documents\000-Mgmt-CH\600-Departments", "grey")
Call ColorizeOneFolder ("\\Mailbox - Dan Wilson\Inbox\Customers", "grey")
End Sub
When you move sub-folders between folders, they should retain their
color only until the next time you restart Outlook.
From what I have read this is unfortunately not possible in Outlook 2007.
It is possible in Outlook 2010 using MAPIFolder.SetCustomIcon. See MSDN for more details: http://msdn.microsoft.com/en-us/library/ff184775.aspx
Switching the list of MAPIFolder methods between 2010 and 2007 on the following MSDN webpage shows the SetCustomIcon method for 2010 only: http://msdn.microsoft.com/en-us/library/bb645002.aspx

Categories