Showing posts with label Windows desktop app. Show all posts
Showing posts with label Windows desktop app. Show all posts

Tuesday, August 9, 2011

How to Create Windows Services

What are Windows Services


  • Windows Service is a long running executable that perform specif function.

  • They do not require user intervention.

  • Windows services can be configured to start when the operating system is booted and run in the background as long as windows is running , or can be started/stopped manually when required.

  • Windows services can be developed using Microsoft visual studio.

  • Services can execute even when the user is not logged in.

Friday, July 1, 2011

How to move your heavy attached files in a mail to your peronal website

Embed this VBA Macro in your Outlook :
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
 Dim totalSize As Double 'to store total size of the attachments
 Dim FileName As String  'path for the temp folder
 Dim strBody As String
 Dim strUname As String
 Dim i As Integer
 totalSize = 0
 strBody = "The attached files are placed in the below location" & vbCrLf
 i = 1
 strUname = Environ("USERNAME")
 If Item.Attachments.Count <> 0 Then 'Check if files are attached
   For Each At In Item.Attachments
       totalSize = totalSize + At.Size
   Next At
 'Check the total size of attached files are greater than 1MB
 If totalSize >= 10 Then
   For Each Atmt In Item.Attachments
      strBody = strBody & "http://mysite/personal/" & strUname & "/Personal%20Documents/" & Atmt & vbCrLf
      FileName = "C:\Users\" & strUname & "\AppData\Local\Temp\" & Trim(Atmt.FileName)
      Atmt.SaveAsFile FileName 'Save the attachments to Temp folder of your system
      UploadFile "C:\Users\" & strUname & "\AppData\Local\Temp\" & Atmt, "http://mysite/personal/" & strUname, "Personal Documents/" & Atmt.FileName, "Test title", "Test checkin comment"
   Next Atmt
 End If
  
   For i = 1 To Item.Attachments.Count 'Delete Attached files in mail
    Item.Attachments(1).Delete
   Next i
  
    Item.Body = Item.Body & strBody
    'MsgBox ("Total Size:" & totalSize & "KB")
    MsgBox "Done"
  
End If
 
 End Sub

Function StringToByteArray(str)
  Set stream = CreateObject("ADODB.Stream")
  stream.Open
  stream.Type = 2 ''adTypeText
  stream.Charset = "ascii"
  stream.WriteText str
  stream.Position = 0
  stream.Type = 1 ''adTypeBinary
  StringToByteArray = stream.Read()
  stream.Close
End Function

Sub UploadFile(sourcePath, siteUrl, docName, title, checkincomment)
strHeader = "method=put+document%3a12.0.4518.1016" + "&service_name=%2f" + "&document=[document_name=" + docName + ";meta_info=[vti_title%3bSW%7c" + title + "]]" + "&put_option=overwrite,createdir,migrationsemantics" + "&comment=" + "&keep%5fchecked%5fout=false" + vbLf
byteArray = StringToByteArray(strHeader)
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 1 ''adTypeBinary
stream.Write byteArray
Set stream2 = CreateObject("ADODB.Stream")
stream2.Open
stream2.Type = 1 ''adTypeBinary
stream2.LoadFromFile sourcePath
stream2.CopyTo stream, -1
stream.Position = 0
Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "POST", siteUrl + "/_vti_bin/_vti_aut/author.dll", False
xmlHttp.setRequestHeader "Content-Type", "application/x-vermeer-urlencoded"
xmlHttp.setRequestHeader "X-Vermeer-Content-Type", "application/x-vermeer-urlencoded"
xmlHttp.setRequestHeader "User-Agent", "FrontPage"
xmlHttp.Send stream
 If xmlHttp.Status = 200 Then
 If InStr(xmlHttp.responseText, "successfully") = 0 Then
  MsgBox "ERROR:" & vbCrLf & xmlHttp.responseText
  Else
  ''Checkin
  strHeader = "method=checkin+document%3a12.0.4518.1016" + "&service_name=%2f" + "&document_name=" & docName + "&comment=" + checkincomment + "&keep%5fchecked%5fout=false" + vbLf
  Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
  xmlHttp.Open "POST", siteUrl + "/_vti_bin/_vti_aut/author.dll", False
  xmlHttp.setRequestHeader "Content-Type", "application/x-vermeer-urlencoded"
  xmlHttp.setRequestHeader "X-Vermeer-Content-Type", "application/x-vermeer-urlencoded"
  xmlHttp.setRequestHeader "User-Agent", "FrontPage"
  xmlHttp.Send strHeader
  End If
  End If
  If xmlHttp.Status / 100 <> 2 Then
   MsgBox "ERROR: status = " & xmlHttp.Status & vbCrLf & xmlHttp.responseText
   End If
End Sub
Function UserNameWindows() As String
Dim UserName As String
UserName = Environ("USERNAME")
'return UserName
End Function










 

Thursday, May 19, 2011

How to force uninstall a program you cannot uninstall

  1. Click Start and choose Run in the menu (If you're using Windows Vista then press Win+R on your keyboard).
  2. Type regedit and hit Enter.
  3. On the left side is the registry settings tree, use it to go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
  4. Inside that key you'll find a lot of keys that belong to different programs. Some are named after the program's name, others as a mix of numbers and letters that makes no sense. Look through each of them until you find one that has the key DisplayName (on the right) with your program's name in it.
  5. Notice the key UninstallString - this key points to the uninstall program, and the log file usually resides in the same folder as that program.
  6. If you delete the key in which you've found the DisplayName key with the value equal to your program's name, then your program won't appear on the Add/Remove programs list

Tuesday, May 10, 2011

How to add a string value inside a registry in C#?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Permissions;
using Microsoft.Win32;
namespace Software_EditRegistry {

public partial class Form1 : Form
{

{
InitializeComponent();
}

{

public Form1()
private void button1_Click(object sender, EventArgs e)// Set String Value inide the registry.

}
}
}
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\", "C:\\Users\\XXX\\Desktop\\Source Code\\XXX.exe","WINXPSP2", RegistryValueKind.String);

read more : http://www.java2s.com/Tutorial/VB/0440__Windows/GetstringvaluefromRegistry.htm

Tuesday, May 3, 2011

How to run windows program automaticaly when system starts up

1.Click windows icon
2.Type gpedit.msc in search box
3.Goto User Configuration > Windows Settings >Scripts(Logon/Logoff)
4. Double-Click Logon , add the logon script and press OK.