Screen Capture the mouse

18 06 2009

OK, this is rather arbit and somewhat stupid. Still…

Press Print Screen. It gives you a capture of the current screen. The mouse is missing.

Open control panel, go to mouse options then cursor options. Print Screen that, and Photoshop the mouse with some outer shadows.

I told you it was kinda arbit.





WnetAddConnection2A

18 06 2009

WNetAddConnection2A is essentially a WinAPI function that allows you to add/mount Windows share connections (Samba shares if you will)… it lets you specify a comp name, username and password. Now the problem is, once in a while, you may encounter 1219 error. This translates to multiple connections from the same comp to the remote comp – which is apparently bad in Windows. Until today, I used to restart both comps to make this go away. Dont do that. Goto command line, do a net use and see who/what is using the connections. Then do a net use * /delete to remove them all… google more to find out how to remove only what you want or better still, experiment.





Aero in Remote Desktop

29 05 2009

YES! Remote Desktop now does AREO!! now = Windows 7

Basically they put in more capabilites into the RDP client. Wanna test it? You need to access a Win 7 (or maybe even vista-not sure) comp FROM a win 7 comp… it works only then.

I need to check out how games will perform through RDP now :)





Data Binding

29 05 2009

Back in PHP, I wrote loops. Loops that would take data from a single select query (no, I didnt write multiple select statements… you’re funny :) )… and then put that data out in columns etc

ASP.NET – say hello to DataBinding. Apparently its been around for quite some time, but it used to be slow. And now its not. So, there is a DataList object. Kinda simple. But use GridView. Its newer and better.

Essentially, you write a stored procedure giving you the output you want after accepting some input variables. Click on the GridView. That cute little “>”  gets a click and you add your data source. Define your connection string in web.config (so that it can be changed later). Enjoy the GUI. I am storing the login name in the Session info. Will find out soon enough if this is the right thing to do. It even lets you do a test query by allowing you to specify the input variables… CUTE too CUTE :)

Since the stored procedure gives you certain columns, that is cool and data-bound. Now you may want to change lots of stuff.

1. You want to have your own column where you add data on the fly. So add a new column. A Template column if the others are not nice. Add whatever you want inside <ItemTemplate> tags inside this

2. For GirdView, there is a rowbound event handler. Once a row is populated with bounded sql data, this function gets called… and you get to meddle with that row (change the values fom sql.. use those values to generate data for your new columns… do whatever)

3. Rowcommand is what you use to monitor clicks. The event argument e carries data. Make sure to add proper commandnames and commandarguments if they are buttons. Do this in the rowbound function.

Another nice thing is that it auto-sorts when you click on the column header names. It basically calls Rowcommand. Now if you redefine your rowcommand, just dont do anything if you detect a sort command (Commandname is “sort” ) I guess it calls another “sorting” function that does the trick after that.





SQL Stored Procedures

29 05 2009

Apparently this is the STANDARD way to do stuff :)

So, here’s the story… Microsoft has its own modified version of SQL (called T-SQL or Transact SQL)… this is what comes with those SQL Servers that get installed when you put Visual Studio… there is this neat tool called SQL Management Studio… Use it. Its a nice Graphical Interface. Saves you loads of time writing queries to do some basic stuff.. Apparently the newer 2008 SQL Managemet studio has debugging feature but 2005 doesnt :(

Anyway, so in PHP I was used to writing queries in the php code itself.. I did that for my ASP.NET code too… only to read later on that stored procedures are the way to go and then saw a small sentence in the Software Requirement Specs that said “Standard security and error checking measures… 3)Stored procedures for SQL”

So, this is how it works. Instead of giving full access to the DB user, you give them access only to the procedures. And since you have written the procedure and they open up only a very limited window for meddling with stuff… its secure :)

I am using the SQL logins with inbuilt windows authentication… one of the many advantages of being on a domain account

A few important things to remember… you pass values to the procedures through ASP.NET. Carefully specify the format field (if its nchar… coz apparently the AddWithValue() function does a String lenght of the passed char and puts that as nvarchar… ). Queries can be returned directly. No need to specify a spearate return variable etc. But you can if you want to. Just specify the direction as output (even in sql)





ASP.NET

20 05 2009

seems to be AMAZING!

Pretty much the same functionality as the standard Windows .NET framework…  Its so much easier than Javascript (mainly coz of Visual Studio :) ) And I personally find it slightly better than PHP too… well I am yet to find out how to do SQL stuff in it… but again, something nice is bound to exist :)

The Button Drag Drop thing is AWESOME! So are the text boxes and all the other things… IIS has little configuration to meddle with and Visual Studio just publishes it all with dlls directly into that folder :)

F5 previews the web-page in a virtual server by Visual Studio…. Man, this is really good…. I mean DreamWeaver was made solely for this purpose and Visual Studio (meant in my opinion more for system application development) is able to do the same things… now if only they can add full CSS support… that would be marvellous…

EDIT: IT DOES HAVE FULL CSS SUPPORT!!





Hidden Windows Share

20 05 2009

The nice thing about domain accounts is that if you have logged into another comp using a domain accout, it CREATES an account on that system. Next time you access that comp using windows share, it lets you see your profile data directly :)

Now, if you have admin privileges on that comp (or maybe even otherwise)… you basically get to see ALL the data on that comp… now although these things may not show up when you do a \\computer-name in explorer, here’s what you can do

\\computer-name\C$

Basically, add a $ at the end of C … this will show you contents of C:

Another neat trick is \\computer-name\ADMIN$

that opens up the windows folder (note you cannot exactly use %windir% coz that will be the local system variable :) )

Neat na? Of course it is.





Pstools

20 05 2009

http://technet.microsoft.com/en-us/sysinternals/default.aspx

Sysinternals was a company founded by one person. They made awesome software that was able to meddle with intricate windows stuff… so, M$ bought it :) (kinda expected)

Anyway, the point of this post is basically psshutdown.exe. This exe is kinda neat. It lets you Shut Down, restart, standby, hibernate and do other things to your computer and even a remote computer. M$’s shutdown.exe that comes bundled with all comps cannot standby or hibernate (it can do the other things on a remote system too, but it uses the same account credentials as the user running it even on the other system… and that user needs to be admin on the remote system)

The other way to accomplish standby and hibernate is to do this

rundll32 powrprof.dll SetSuspendState Hibernate
rundll32 powrprof.dll SetSuspendState Standby

Programmatically, there will be a Win API exposure to powrprof…

But coming back to psshutdown, the way I think (and proved) it works is

1. It takes in username/password of remote system from command line

2. Uses windows share to copy itself (actually a smaller copy with some other name) onto the remote system’s system32 folder… (another fun thing here to be described in another post)

3. Registers this copied exe as a service and starts it to do stuff

Seems like a long way to do things right? Yeah, I guess it is… there is also something called WMI… but that needs special firewall exceptions (Atleast with the group policy that I am working with)… if you use WMI, then Win32_OperatingSystem or Win32_Process can be used… again, the Win32_OperatingSystem Win API Class does not let you standby or hibernate… so use process to do the rundll32 thing….

It took me ONE FULL FREAKING DAY to figure that out… (that and the fact that I almost had a fully functional WMI apsx page and then decided not to use that… and was then told to use psshutdown… and then continued and found out this :) )

3rd day :)





WOL

20 05 2009

After having dabbled with it for some time in college, I finally got a chance to “work” on it… Guess M$ is my first employer :) Working to make an ASP.NET application for remotely doing these things… A few findings may find their way into this blog… In general, IT WORKS!!! (although within the same subnet)





TeraCopy

13 05 2009

So, I was copying stuff onto people’s external USB HDDs… mostly movies… the thing is that I had to copy from multiple folders onto their HDD… and the way it works with external HDDs is that if you copy multiple files in parallel, the combined time taken is waaaaaaay more than doing the same copies sequentially. This is because of certain limitations

1. Your comp’s main HDD has a limited number of read/write heads.

2. The external USB HDD has a limited number of read/write heads.

This translates to the same head moving around repeatedly in case of parallel transfers. It invariably so happens that the time it takes for the head to move is a lot and the net data rate reduces.

So, what is needed is some sort of a utility that can make the copying sequential… something that will let you queue up stuff…

One such free thing is TeraCopy http://www.codesector.com/teracopy.php One warning about this thing though… of the nearly 30-40 times that I used it, it crashed twice while trying to copy files… dont know why… but it didnt repeat, so its happy now :) One dangerous thing about it though is that after you select a file and decide to remove it from the copy queue, delete will try to delete the file from the main HDD!!

I am writing my own thing in C# .NET just for fun (multi threading et al)… will probably blog about it again later….

So, thats it… TeraCopy… I am calling mine OmegaCopy :P