Compiling an Application to require UAC Rights Elevation

Recently I was developing an application that played around with my services.  I kept running into the access denied message.  After some research I found out it was related to UAC.

After compiling the application and right-clicking to run as administrator, I wanted something that would force my app to be run as administrator automatically…. thus my search began:

The solution came from Judah Himango on the following post:  http://stackoverflow.com/questions/227187/uac-need-for-console-application

To implement what he’s talking about do the following:

1. Download and install the Windows SDK from http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=11310

This SDK contains the MT command referenced in Judah’s response.

 

2. Add a program manifest to your application:

image

 

3. Modify the manifest to reflect the new “requireAdministrator” status as below:

image

 

2. Paste in the following line in your projects post-build step under Visual Studio:

(for 64-bit systems)

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\mt.exe" -manifest "$(ProjectDir)$(TargetName).exe.manifest" -updateresource:"$(TargetDir)$(TargetName).exe;#1"

 

(for 32-bit systems)

"C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bin\mt.exe" -manifest "$(ProjectDir)$(TargetName).exe.manifest" -updateresource:"$(TargetDir)$(TargetName).exe;#1"

 

image

 

Compile and you’re done.  On Windows 7, vista and 2008 (r2), you should see a little shield next to your icon indicating that administrator privileges are required to run your app.

image

 

Hope this helps others out there!   Let me know by posting your comment below.

PowerShell: Test-Host

       
       .Synopsis
            Test to see if this host is online and accessible.
       
        .Description
            Sends two pings the the hostname, then attempts to access the admin share for this host.
       
        .Parameter HostName
            Hostname or IP address to be tested.
       
        .Parameter skipPingTest
            This will allow you to skip the ping test when validating a host is up.
       
        .Parameter skipShareTest
            This will allow you to skip the share test when validating a host is up.
       
        .Example
            Test-Host DanielPC
            Description
            ———–
            Tests the host with both two pings and an admin share connection test.
           
        .Example
            Test-Host DanielPC -p
            Test-Host DanielPC -skipPingTest
            Description
            ———–
            Tests the host by admin share test and skips the ping test…
       
        .Example
            Test-Host DanielPC -s
            Test-Host DanielPC -skipShareTest
            Description
            ———–
            Tests the host by ping test only and skips the admin share test…
           
        .Example
            "DanielPC " | Test-Host
            Description
            ———–
            Receives input from the pipeline for testing if a host is online or not.
           
        .OUTPUTS
            Boolean
       
        .NOTES
            NAME:       Test-Host
            AUTHOR:     Daniel Moran
            Website:    http://www.moranit.com
            LASTEDIT:   04/18/2011
            #Requires   -Version 2.0
       
        .LINK
            https://danielheth.com/2011/04/18/powershell-test-host/

Wireless provides an easy Virtual GPS device

858001-1053401So I’ve done the research and have determined what Skyhook wireless and other Wi-Fi Mapping companies has done and it is ingenious!  Ok, let me set the scene:  Say you’re walking through the forest and spot an interesting tree.  Right next to that is another interesting tree.  If you end up walking in circles in the forest and you see those same two interesting trees you know where you are at that instant right?

Well… apply that same line of thinking to wireless access points (AP) anywhere in the world.  Skyhook has went around the world mapping out all of the access points and linking them to GPS locations… Thus if your in a certain location and you see 5 wireless access points around you and one of them has a 99% signal.  Odds are you are extremely close to that access point right? Send the information about that access point (like ssid and/or mac) to skyhook and they’ll send you back your most likely position.  This is the perfect mix of technology and good old fashion logic.

Well I’ve spent the time putting together the components needed to do this very same mapping and I’m sharing it with you guys free…  You will need a few things… a laptop with Wi-Fi and a GPS device. 

As far as code goes, you’ll need the following two visual studio 2008 projects:

1. WifiScanner (755kb) – a program to be run on the laptop.  It uses netsh and GPS (41kb) to map out all of the surrounding Wi-Fi access points. This map is uploaded via a SOAP call to our next program needed…

2. SOAP vGPS (56kb) – a server side application for databasing the mapped access points and returning results for finding your virtual GPS location.

The great thing about this project is the bigger the map gets the more accurate the vGPS becomes.

There are two directions these VS projects can go… the first is to complete the logging feature on the WifiScanner so the data can be captured off-line and uploaded at a later time… or second an offline and portable database can be created for personal use.  This database can be updated as you drive and vGPS can be taken with you so if you are not using the real GPS device, the vGPS can act as a viable alternative.

Comment on all the things you do with this stuff below…

CoolStorage Parameters and Filtering

The documentation for the CoolStorage product is severely lacking!!!  Thus I have decided to document within my blog the stuff they did not or cool things I’ve come across regarding this wonderful database product.

The latest undocumented features of this product are surrounding the parameters feature.  Examine the following code:

    CSList<QuestionResults> objs = QuestionResults.List("SiteID=@s", "@s", "554478");

This is an example of the documented way they describe how to use parameters.

However there is an undocumented way to use parameters:

    CSList<QuestionResults> objs = QuestionResults.List("ResultsText like @r", "@r", "Win7%");

As you can see the “like” can be used to query strings for their content. You can even use the “%” as the expected “like” wild card.

Digg This

SQL and PowerShell Connectivity

Do you have a SQL server you want to gain access to from PowerShell?  Well you’re in luck, so did I…

My recent connection to BigFix has prompted me to gain access to the BFEnterprise database… Thus I have come up with the following PowerShell function to gain access to my BigFix Server DB installation:

 

function SQLExecute {
    param (
        [string]$SQLSERVER = “<MySQLServerName>”,
        [string]$Database = “BFEnterprise”,
        [parameter(Mandatory = $true)]
        [string]$cmd
        )
    $con = “server=$SQLSERVER;database=$Database;Integrated Security=sspi”
    $da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con)
    $dt = new-object System.Data.DataTable

    $da.fill($dt) | out-null

    return $dt

}

 

This function will return an object(s) of what you requested. 

For Example:  SQLExecute –cmd “select * from computers”

will select all of the registered computers within your BigFix installation.

Or if you have run the Property Mapper utility the following SQL will return object(s) of your computer ID / Computer Name:

SQLExecute -cmd “select ComputerID, ResultsText as ‘Computer Name’ from QUESTIONRESULTS QR where (QR.SiteID = (select SiteID from PROPERTYIDMAP where propertyname like ‘Computer Name’)) AND (QR.AnalysisID = (select AnalysisID from PROPERTYIDMAP where propertyname like ‘Computer Name’)) AND (QR.PropertyID = (select PropertyID from PROPERTYIDMAP where propertyname like ‘Computer Name’))”

 

More to come… have fun!

Digg This

Post to your Twitter Account using VB.net

That’s right guys and gals, you can very easily and quickly post to your twitter account using Visual Basic.net.  The function below is a fully functional VB.net 2008 Twitter Posting function.

Simply call the function below as follows:

PostonTwitter(“username”,”password”,”what i want to post”)

 

Public Sub PostonTwitter(ByVal userName As String, ByVal password As String, ByVal updateMessage As String)
Dim wc As Net.WebClient = New Net.WebClient()
wc.Credentials = New Net.NetworkCredential(userName, password)
Net.ServicePointManager.Expect100Continue = False
Dim updateMessageBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(“status=” + updateMessage)
‘Use UTF8 to get it properly encoded if you use characters like ç ã etc…
wc.UploadData(“http://twitter.com/statuses/update.xml&#8221;, updateMessageBytes)
End Sub

Windows Home Server Programming

There is an awful lot of crap to wade through when you want to program a console application with a tab and settings section.

Here is an extremely basic breakdown of what you’ll need before starting to program.

1. Microsoft Visual Studio 2008

2. Microsoft Windows SDK available at:  http://go.microsoft.com/fwlink/?LinkId=94640 (Specifically the ORCA tool)

3. A Windows Home Server… of course.

4. Idea for a project… (here is a link to the sample project the MSDN site stepped me through creating)

5. Lastly the HomeServerExt.dll and Microsoft.HomeServer.SDK.Interop.v1.dll files copied from your WHS c:\program files\Windows Home Server directory.

 

Once you have all of these things, you’ll be ready to program… I think… I’m gotten thru all of the project stuff, created my installer, but I didn’t have the Windows SDK before hand.  I’m downloading/installing it now in order to do the final step of using ORCA to edit the msi file so WHS will recognize it as an Add-In.

For additional references and info on programming for your home server… checkout Microsofts website:  http://msdn.microsoft.com/en-us/library/cc952481.aspx

Restart Notice

Here is a copy-cat program of my NTBackupStatus application. It is a stripped down version where if triggered shoots off an email to me… that’s it. I have it setup in Scheduled Tasks on each of the servers I manage. This task is configured to run only when the system starts up, in other words when the server restarts because they should be on 24×7.

The Premise: To help me monitor unexpected server restarts.

How It Works: This program utilizes a settings ini file which stores smtp information and login info to send the emails.

I’ve uploaded it for everyone to use on their own servers… Have Fun.

As usual, I provide no warranties and no responsibility for anything that goes wrong… However post your comments and I’ll try to help as best I can.

To Install:
Extract the zip file and copy the “HethTools” directory to the root of the C:\ Drive. Then update the RestartNotice.ini file as needed. Lastly, add a scheduled task to run the RestartNotice.exe program at system startup.

Click here to Download Source and Executable

NT Backup Status

So, I manage 4 Windows 2003 Servers for my customers. I have full control and decision making abilities on nearly every aspect of these servers. The biggest problem is my limited budget. Therefore often write my own programs to do various things to help in the daily administration of these systems.

The Premise: To help me monitor their backup solutions I have written NT Backup Status. It is a very simple VS 2008 VB command line application that is triggered via Scheduled Tasks every day at 8am.
I am using NTBackup to archive my customers data. This daily backup task is set to stop no matter what at 7 hours after it starts at 1am. That way my customers are not impacted by a slow unresponsive server during business hours.

How It Works: The first thing this application does is to read in the latest backup log from NTBackup. It then scans the contents for indications of failure and if found triggers an email to me.
This program utilizes a settings ini file which stores smtp information and login info to send the emails as well as the directory where NTBackup saves its log files.

I’ve uploaded it for everyone to use on their own servers… Have Fun.

As usual, I provide no warranties and no responsibility for anything that goes wrong… However post your comments and I’ll try to help as best I can.

To Install:
Extract the zip file and copy the “HethTools” directory to the root of the C:\ Drive. Then update the NTBackupStatus.ini file as needed. Lastly, add a scheduled task to run the NTBackupStatus.exe program at your desired time… typically after NTBackup has finished it’s job.

Click here to Download Source and Executable

Retrieve Username

There comes a time in almost every program when you want to know who is the currently logged in user… here’s a little function to do that…

Declare Function GetUserName Lib “advapi32.dll” Alias _
“GetUserNameA” (ByVal lpBuffer As String, _
ByRef nSize As Integer) As Integer

Public Function retUserName() As String
Dim iReturn As Integer
Dim userName As String
userName = New String(CChar(” “), 50)
iReturn = GetUserName(userName, 50)
retUserName = userName.Substring(0, userName.IndexOf(Chr(0)))
End Function